bethskurrie
2018-03-24 03:39
has joined #pact-js

mboudreau
2018-03-26 10:38
has joined #pact-js

bethskurrie
2018-04-05 04:06
/github subscribe pact-foundation/pact-js

bethskurrie
2018-05-02 04:56
/github unsubscribe pact-foundation/pact-js commits

bethskurrie
2018-05-02 04:57
/github unsubscribe pact-foundation/pact-js commits

bethskurrie
2018-05-02 04:57
/github unsubscribe pact-foundation/pact-js deployments public

sgleadow
2018-05-09 07:06
has joined #pact-js

vinod.baradwaj
2018-05-09 07:08
has joined #pact-js

abubics
2018-05-09 07:11
has joined #pact-js

rgshah781988
2018-05-09 07:16
has joined #pact-js


matt.fellows
2018-05-09 07:20
has joined #pact-js

mboudreau
2018-05-09 07:22
@rgshah781988 that error message has nothing to do with pact

mboudreau
2018-05-09 07:22
that's an assertion error

matt.fellows
2018-05-09 07:22
exactly

mboudreau
2018-05-09 07:23
must be coming from your tests

matt.fellows
2018-05-09 07:23
you?re not properly handling the promise, it seems

matt.fellows
2018-05-09 07:23
if you can share your test code, we can probably help


mboudreau
2018-05-09 07:24
but remember that we're not here to fix your tests for you, there's plenty of documentation out there, so please try your best before bringing it to us as we're busy as well :slightly_smiling_face:

rgshah781988
2018-05-09 07:24
Yes sure

rgshah781988
2018-05-09 07:25
I got stuck since 5 days


mboudreau
2018-05-09 07:26
did you follow an example on how to use pact?

rgshah781988
2018-05-09 07:26
Yes

rgshah781988
2018-05-09 07:26
When I use matchers

mboudreau
2018-05-09 07:26
`const { Pact, Matchers } = require('../../../dist/pact')` ...this doesn't seem right..

rgshah781988
2018-05-09 07:26
THen i am facing issue

mboudreau
2018-05-09 07:27
can you post the link of the example you're following?

rgshah781988
2018-05-09 07:27
Actually, Example is working.

rgshah781988
2018-05-09 07:28
pact-foundation e2e folder

rgshah781988
2018-05-09 07:28
I am trying my application with it.

rgshah781988
2018-05-09 07:28
I am getting pact file creating successfully without using matchers

mboudreau
2018-05-09 07:29
...I asked for the link to the example

rgshah781988
2018-05-09 07:29
When I use matchers then I am getting error.


mboudreau
2018-05-09 07:32
right. An where in this example are we doing `expect(response.data).to.eql(EXPECTED_BODY)`?


mboudreau
2018-05-09 07:34
so, you took 2 different examples and mashed it together

rgshah781988
2018-05-09 07:34
I have updated code as per this details

mboudreau
2018-05-09 07:35
the line before `expect(response.data).to.eql(EXPECTED_BODY)`, add this: `console.log(JSON.stringify(response.data, null, 2));console.log(JSON.stringify(EXPECTED_BODY, null, 2));`

mboudreau
2018-05-09 07:35
run the example again

rgshah781988
2018-05-09 07:35
This example , I need to use matchers

mboudreau
2018-05-09 07:35
and see if they're equal

rgshah781988
2018-05-09 07:38
Expect condition is failing. I am getting console response

mboudreau
2018-05-09 07:38
anywho, I need to get home. I suggest that you try to understand how pact works before you start combining tests together. There's plenty of resources out there

mboudreau
2018-05-09 07:38
the expect is failing because the objects are not the same

mboudreau
2018-05-09 07:38
one is the pact definition, the other is the action object coming from the mock

mboudreau
2018-05-09 07:38
they're 2 different things

mboudreau
2018-05-09 07:38
one explains the format, the other returns the end results

rgshah781988
2018-05-09 07:39
Thanks you so much @mboudreau

mboudreau
2018-05-09 07:39
point is, you're not suppose to do an expect on the whole object

mboudreau
2018-05-09 07:40
do an expect on individual properties

mboudreau
2018-05-09 07:40
or keys if needed

mboudreau
2018-05-09 07:41
but really, by adding those tests, you're not testing your code, you're testing the mock service. We have plenty of tests for those, and I assure you they work. You should be testing your own code

matt.fellows
2018-05-09 07:41
I think we should update the examples. The original `dog api` examples are so contrived they are useless - i.e. they encourage testing the whole object. I?ll put an issue in pact-js for us to fix them

matt.fellows
2018-05-09 07:50
:point_up:

rgshah781988
2018-05-09 08:23
ok

rgshah781988
2018-05-09 13:37
How can I get dynamic response from pact files ? I tried using matchers such as like,eachlike

rgshah781988
2018-05-09 13:38
I am working on API which has POST call with different payload values.

rgshah781988
2018-05-09 13:38
According response changes.

slack1
2018-05-09 20:00
has joined #pact-js

brentbarker9
2018-05-09 20:56
has joined #pact-js

mboudreau
2018-05-09 22:25
you don't. The point of pact is to generate a new response for each different request, hence you're now mapping all of the "interactions" as part of the "contract"

mboudreau
2018-05-09 22:26
you can reuse responses if you'd like for a different interaction though

abubics
2018-05-10 01:37
I think ?dynamic response? isn?t quite what you mean :slightly_smiling_face: You have - variable request (on parameters), and - deterministic response fields (constant, or from parameters), or - flexible response fields (?dynamic? such as a fresh ID).

abubics
2018-05-10 01:37
for all response fields, you may want to use a flexible matcher

bethskurrie
2018-05-10 04:01
That's fine @rgshah781988. Just make a different interaction (request/response) for each different POST example. If the post is to the same URL, you'll need to make sure that only one interaction is mocked at a time, so the mock knows which response to return. That is, you'll have to do a set up/tear down for each interaction (which is actually the recommended way to use pact anyway).

rgshah781988
2018-05-10 05:47
Yes, This what I expect

rgshah781988
2018-05-10 05:47
So, how to do flexible matcher

abubics
2018-05-10 06:09
Have a look in the docs: https://github.com/pact-foundation/pact-js#matching There?s an example under the heading *Match based on type* :slightly_smiling_face:

rgshah781988
2018-05-10 06:09
ok tysm

matt.fellows
2018-05-10 07:33
Just released a neat little video showing some of the features of Pact JS and integration with the broker: https://github.com/pact-foundation/pact-js/#examples

matt.fellows
2018-05-10 07:33
Useful?

rgshah781988
2018-05-10 09:15
Pact JS and integration with the broker . All inforamtion is clear with pact-broker

matt.fellows
2018-05-10 11:05
:+1:

abubics
2018-05-11 05:28
Having the console recording is nice, but with no scrub bar, it all disappears before I can read it :slightly_smiling_face:

abubics
2018-05-11 05:28
Maybe https://asciinema.org/ would be easier to use?

matt.fellows
2018-05-11 06:17
that?s what I used to create it. The annoying thing about asciinema is that it doesn?t play - I should probably like to it though, good point

abubics
2018-05-11 07:11
you mean there?s no embeddable player? http://asciicinema.org is covered in them :s I thought it was part of the package

matt.fellows
2018-05-11 07:12
As in, you can?t embed the player into a GitHub README (or maybe you can now). You can only put the image and a link

matt.fellows
2018-05-11 07:12
That?s why the SVG plugin exists - because it plays, so you can see it

matt.fellows
2018-05-11 07:13
so the best of both words is the SVG in the readme (because it looks sexy and can play) and a link to the player, where you can control the speed?

abubics
2018-05-11 07:21
right, because you need to source the player script

abubics
2018-05-11 07:22
I guess you could iframe it . . . nothing but hacks to workaround that :stuck_out_tongue:

abubics
2018-05-11 07:22
but if the svg linked to a player, I think that?d be good enough

rgshah781988
2018-05-18 10:18
No update or message in pacts js since last 7 days :sunglasses: Is anyone working with pactjs or not ?

matt.fellows
2018-05-18 11:20
@rgshah781988 hehehe

matt.fellows
2018-05-18 11:20
People still migrating (and using) the gazillion other channels they were communicating to us on.

matt.fellows
2018-05-18 11:21
But I like to think, it?s so amazing and easy to use, that noone needs to ask questions about pact-js :slightly_smiling_face:

rgshah781988
2018-05-18 11:24
@matt.fellows gazillion ? can you share link of it ? I can find some solution or help.

matt.fellows
2018-05-18 12:47
what do you mean, sorry?

matt.fellows
2018-05-18 12:48
I was just remarking that the move from gitter/google groups/etc. to Slack is new, so it?s still new place to grow this community, hence not many conversations yet

thomas.heilbronner
2018-05-21 09:24
has joined #pact-js

avinash.eediga
2018-05-23 05:56
has joined #pact-js

avinash.eediga
2018-05-30 00:41
hi guys

avinash.eediga
2018-05-30 00:41
how do i add authorization headers to access my endpoint to verify

matt.fellows
2018-05-30 02:39
@avinash.eediga could you please provide more info? Also, have you seen `customProviderHeaders` in https://github.com/pact-foundation/pact-js#verification-options?


brentbarker9
2018-05-30 20:17
Can I match based on the key? For example, I have a payload that returns with `{"monthJan":5}`, and every month that key will change (monthFeb, monthMarch, etc..)

mboudreau
2018-05-30 22:19
you can match using a regex

mboudreau
2018-05-30 22:19
wait, I think that might be on the value, not the key

matt.fellows
2018-05-30 22:39
Yep, you can?t do it on the keys yet I?m afraid. That?s something slated for v4 of the spec: https://github.com/pact-foundation/pact-specification/tree/version-4

mboudreau
2018-05-30 22:57
@brentbarker9 is there a way to change the data structure? I can't imagine monthJan/monthFeb/etc to be a great way of doing it since the key changes. It's adding more complexity than needed. What are you trying to accomplish with this data structure?

brentbarker9
2018-05-30 23:05
Yeah, talked to the dev. They are going to change the data structure to make a little more sense and not have the keys dynamic

brentbarker9
2018-05-30 23:06
Very cool it is going to be in v4 though

brentbarker9
2018-05-30 23:06
thanks!

g.r.mccann
2018-05-31 10:39
has joined #pact-js

dervis4
2018-06-07 08:26
has joined #pact-js

vinny
2018-06-15 06:01
has joined #pact-js

vinod.baradwaj
2018-06-21 10:51
is it possible to pass query parameter values in array ? something like this `page=[1]&limit=[25]&fql=[]`

bethskurrie
2018-06-21 10:51
It should just be a string

bethskurrie
2018-06-21 10:52
I don't think it would be treated any differently to any other string.

bethskurrie
2018-06-21 10:52
`{page: "[1]"}`.

bethskurrie
2018-06-21 10:52
Are you trying to work around some limitation in pact, or is that what your API requires?

vinod.baradwaj
2018-06-21 10:57
this is what my API requires

bethskurrie
2018-06-21 10:57
Should be fine. Why do you ask? Have you had problems?

vinod.baradwaj
2018-06-21 11:01
no problem.. i just wanted to try that

ragarwal
2018-06-22 03:49
has joined #pact-js

abubics
2018-06-22 10:17
Doesn't sound very consumer-driven :P

wchuang
2018-06-22 16:56
has joined #pact-js

wchuang
2018-06-22 16:57
Hi, I am new on pact. I am having some issue with regex matching on a request, is not matching any other value after the one specified in generate. I noticed if I remove manually from the json the [0] it then start to work. how should I setup in order to allow any value to be match? any idea?

bethskurrie
2018-06-23 23:46
Something is wrong with the serialisation of the query. It should be an object, not a string. @matt.fellows does pact js turn the query in to a string, or does it pass the object through?

matt.fellows
2018-06-24 00:48
I'll double check Beth. It should turn it into an object

bethskurrie
2018-06-24 00:51
@wchuang can you post the mock service logs?

matt.fellows
2018-06-24 01:12
@bethskurrie this is what the framework serialises before sending over the wire to the mock service: ``` "request": { "method": "GET", "path": "/animals/available", "query": { "page": { "json_class": "Pact::Term", "data": { "generate": "1", "matcher": { "json_class": "Regexp", "o": 0, "s": ".*" } } } } } ```

matt.fellows
2018-06-24 01:13
I?m not treating query strings any different to regular parameters, and to my eyes that looks to be consistent

bethskurrie
2018-06-24 01:45
Yep, it looks fine to me.

bethskurrie
2018-06-24 01:47
@wchuang what you see in the pact is not what the mock service uses for matching. The pact is written after the request matching is done.

matt.fellows
2018-06-24 01:56
also that matcher is pretty useless (it?s a regex that matches everything) - you might as well just match on type with `like('1')` which basically matches any string

matt.fellows
2018-06-24 01:58
@wchuang do you mean that when you modify the pact, it fixes your _consumer_ test or the _provider_ verification test?

matt.fellows
2018-06-24 01:59
I?ve just tested that locally anyway using the e2e examples in the repository, and the consumer test passes just fine

wchuang
2018-06-25 15:36
sorry for the delay

wchuang
2018-06-25 15:37
15:36:36 [INFO] ===> Received request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["2"]}), headers: Some({"Authorization": "Basic Og==", "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36", "Accept-Encoding": "gzip, deflate, br", "Cache-Control": "no-cache", "Accept-Language": "en-US,en;q=0.9,it;q=0.8", "Postman-Token": "c9ebfe6b-d8c6-000c-5d03-b31d268636c3", "Accept": "*/*", "Connection": "keep-alive", "Host": "localhost:18119"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } 15:36:36 [INFO] body: '' 15:36:36 [INFO] comparing to expected request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["1"]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {"query": Category { name: "query", rules: {"page[0]": RuleList { rules: [Regex(".*")], rule_logic: And }} }} }, generators: Generators { categories: {} } } 15:36:36 [WARN] No matching request found, sending 404 Not Found

wchuang
2018-06-25 15:37
thanks :slightly_smiling_face:

wchuang
2018-06-25 16:25
I used the regex, because now I am matching anything, but in long term i want to also do assertation on the string itself. i am trying now with like

wchuang
2018-06-25 16:30
service | ===> Received request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["2"]}), headers: Some({"Postman-Token": "866f0fef-1ecd-122c-801b-4480d74c63d2", "Authorization": "Basic Og==", "Accept": "*/*", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36", "Host": "localhost:18119", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9,it;q=0.8", "Connection": "keep-alive", "Content-Type": "application/json", "Cache-Control": "no-cache"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } service | 16:27:40 [INFO] body: '' service | service | 16:27:40 [INFO] comparing to expected request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["1"]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {"query": Category { name: "query", rules: {"page[0]": RuleList { rules: [Type], rule_logic: And }} }} }, generators: Generators { categories: {} } } service | 16:27:40 [WARN] No matching request found, sending 404 Not Found

wchuang
2018-06-25 16:30
no matching with Like, use somethinglike could not a like

wchuang
2018-06-25 16:30
withRequest: { method: 'GET', path: '/api/objects', query: { page: somethingLike('1') } },

wchuang
2018-06-25 16:31
that the test

wchuang
2018-06-25 16:31
and this is the json generated "description": "Get object", "request": { "method": "GET", "path": "/api/objects", "query": "page=1", "matchingRules": { "$.query.page[0]": { "match": "type" } } },

wchuang
2018-06-25 16:31
I just call with /api/objects?page=2

wchuang
2018-06-25 16:32
on the consumer test works, I need then to start the mock service and use is like the real one, here is failing

bethskurrie
2018-06-26 05:55
@wchuang which implementation are you using?

bethskurrie
2018-06-26 05:56
Those aren't the mock service logs from the ruby implementation (used by pact-js)

wchuang
2018-06-26 11:36
Hi beth, sorry for the misunderstanding, as said at the beginning I am new to pact :stuck_out_tongue: I have talked with my qa team, and basically we are using the pact-stub-server to then run the json file. that log come from there


wchuang
2018-06-26 11:36
I guess here is the prob, do you know if these are compatible to be use in that way?

bethskurrie
2018-06-26 11:57
Oh! You'll need @uglyog to help you with that.

wchuang
2018-06-26 12:39
k thanks beth for our help :slightly_smiling_face:

vinod.baradwaj
2018-06-27 06:22
this happens when we use the pact files with stub-server

spai
2018-06-27 10:37
has joined #pact-js

liran.tal
2018-07-05 05:23
has joined #pact-js

bsayers
2018-07-11 08:01
has joined #pact-js

mikey
2018-07-12 21:06
has joined #pact-js


matt.fellows
2018-07-12 21:07
So yep, basically that?s the right one

mikey
2018-07-12 21:13
Cool. You mentioned avoiding karma-pact when possible. Why is that?

matt.fellows
2018-07-12 21:21
Well it?s just a bit more complicated to setup and has some restrictions. The reason is that inside Karma you don?t have access to the filesystem, so you need to configure Pact in your client test and in the Karma config (which starts the mock server, logs etc.). But the big one for me is that it encourages testing via UIs (end-to-end / acceptance style) rather than testing _just_ the collaborating components using pure JS


mikey
2018-07-12 21:23
:ewww:

mikey
2018-07-12 21:24
yeah I?d like to avoid a UI

matt.fellows
2018-07-12 21:24
hehe

matt.fellows
2018-07-12 21:24
that?s not to say that `karma-pact` means you have to test via the UI, but Karma most often is associated with it. If you know what you?re doing (i.e. can structure your tests appropriately) then you?re good :slightly_smiling_face:

mikey
2018-07-12 21:25
right on

mikey
2018-07-12 21:25
thank you for your time! this is helpful info

matt.fellows
2018-07-12 21:25
no worries!

matt.fellows
2018-07-12 21:25
Now, I think I?ve seen your name from somewhere before - you?ve been using Pact for a while yeah?

mikey
2018-07-12 21:26
yessir I have, and with pleasure :simple_smile:

matt.fellows
2018-07-12 21:26
:smile:

matt.fellows
2018-07-12 21:26
Have I seen you on the Pact Broker forums maybe? (i.e. the forum for the hosted product http://pact.dius.com.au ? which is now #pact-broker)

mikey
2018-07-12 21:28
I think you and Beth did a video ?intro to Pact? meeting with us a while ago (for Instructure). Also I?ve asked a few questions in the Google Group and Stackoverflow.

matt.fellows
2018-07-12 21:28
aha! Yes that?s it

mikey
2018-07-12 21:29
thanks to Pact we?ve scaled back our E2E test suite and moved almost all of them to run on deployed ?staging? and ?prod? environments only. So much faster CI!!

matt.fellows
2018-07-12 21:29
Where in discussions with Robert Lamb at the moment

matt.fellows
2018-07-12 21:29
oh cool, that?s really great to hear

mikey
2018-07-12 21:30
excellent, yeah Robert?s leading the Pact adoption for our flagship product

mikey
2018-07-12 21:30
speaking of whom, I have a meeting with him right now :smile:

matt.fellows
2018-07-12 21:30
haha ok

mikey
2018-07-12 21:30
Thanks again, matt! Really appreciate all your help.

matt.fellows
2018-07-12 21:30
say hi (and let him know that when it?s daylight here i?ll be talking with out people about how we can help :smile: )

michael.follmann
2018-07-16 21:38
has joined #pact-js

michael.follmann
2018-07-16 21:54
Hi, I?m trying to integrate Pact JS into a React project. It worked well until I tried to build the application with Jenkins. When I execute `yarn install` I get the following error: ``` `Postinstalled Failed Unexpectedly: Extraction failed for /var/lib/jenkins/workspace/.../node_modules/@pact-foundation/pact-node/standalone/pact-1.52.1-linux-x86_64.tar.gz: Checksum rejected for file 'pact-1.52.1-linux-x86_64.tar.gz' with checksum pact-1.52.1-linux-x86_64.tar.gz.checksum` ``` I doubt that this a Pact JS issue, I?d rather blame Jenkins or Nexus. But I was hoping that maybe you have seen this before and could give me a useful hint how to resolve this. Thank you in advance!

matt.fellows
2018-07-16 22:20
It would be worth trynig to get your hands on `/var/lib/jenkins/workspace/.../node_modules/@pact-foundation/pact-node/standalone/pact-1.52.1-linux-x86_64.tar.gz`

matt.fellows
2018-07-16 22:21
Perhaps there is an intermediate proxy or something and it?s not properly downloading it, so when it does the validation it?s incorrect?

michael.follmann
2018-07-17 07:12
Thank you @matt.fellows! Unfortunately, the workspace is already gone and I can?t reproduce the issue. I can see that this file has been downloaded from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.52.1/pact-1.52.1-linux-x86_64.tar.gz. Maybe it was a temporary issue with GitHub or any network/firewall component that corrupted the artifact.

matt.fellows
2018-07-17 07:14
the old ?turn it on and off again? trick - no worries, glad it?s up and working :slightly_smiling_face:

michael.follmann
2018-07-17 07:39
It?s safe to assume that it was a temporary GitHub issue: https://status.github.com/messages ``` Jul 16, 2018 7:44 PM 20:04 CEST We've discovered the issue causing connectivity failures and are remediating. ``` Thank you for your support! :+1:

matt.fellows
2018-07-17 07:44
no worries

dominic.jones
2018-07-17 07:54
has joined #pact-js

matt
2018-07-18 16:19
has joined #pact-js

liran.tal
2018-07-23 05:43
what?s the status of the pact js framework in terms of supporting parallel tests ? the most prevalent example is jest

matt.fellows
2018-07-23 07:02
It?s possible, albeit you?ll need to follow the caveats outlined in the readme

matt.fellows
2018-07-23 07:02
it?s easiest if the parallelised tests are hitting a different mock endpoint

bethskurrie
2018-07-23 07:10
Easiest == only possible.

matt.fellows
2018-07-23 07:11
or `s/a different mock endpoint/a different mock provider`

matt.fellows
2018-07-23 07:11
you definitely need a different _mock endpoint_ to make tests against a single provider work.


liran.tal
2018-07-23 07:56
alright. going to test that soon and will report back with feedback

matt.fellows
2018-07-23 08:43
Let us know how things go. I should be semi available later on tonight :laughing:

liran.tal
2018-07-23 09:02
no rush, but appreciate it :wink:

antonello
2018-07-26 11:02
has joined #pact-js

codypumper
2018-08-08 14:03
has joined #pact-js

kurst03
2018-08-09 00:29
has joined #pact-js

mbudde
2018-08-09 08:47
has joined #pact-js

liran.tal
2018-08-09 16:50
how much ?beta? is pact-js 6 exactly? :slightly_smiling_face:

matt.fellows
2018-08-09 20:42
More production ready than beta.

matt.fellows
2018-08-09 20:43
It's just the message pact interface that might change. We were wanting more feedback

liran.tal
2018-08-10 08:21
is there a PR or an issue opened on it which I should follow? and is there a list of items that need to land to make 6 ready?

simon.nizov
2018-08-12 09:06
has joined #pact-js

wilkin4
2018-08-12 21:33
has joined #pact-js

nathanrobert.smith
2018-08-13 12:35
has joined #pact-js

dagarwal
2018-08-15 06:44
has joined #pact-js

dagarwal
2018-08-15 06:46
Hi ,is it possible to create interactions in JS like this ?matchingRules?: { ?$.query.var1[0]?: { ?match?: ?regex?, ?regex?: ?.*? }, ?$.query.var2[0]?: { ?match?: ?regex?, ?regex?: ?.*? }, what should i pass in var 2 that my two api calls are successful http://localhost:${PORT}/api/objects?var1=0&var2=25 and http://localhost:${PORT}/api/objects?var1 Is it possible to do by provider states?

matt.fellows
2018-08-15 09:00
Rather than showing the expected pact file, let's start at the start. What's the goal of your test? You can definitely apply matchers to query strings if that's what you're asking

matt.fellows
2018-08-15 09:36
You'll probably want to use a type matcher also, rather than a regex if you don't care about the value

dagarwal
2018-08-15 09:45
I want two tests to work .For example One uses only one parameter and other query uses two parameter .How do i do that


dagarwal
2018-08-15 09:45
like this

dagarwal
2018-08-15 09:46
one is to list the data and in other test we pass one more parameter of sorting

liran.tal
2018-08-15 13:46
@dagarwal there isn?t any problem to do that. what?s your issue?

liran.tal
2018-08-15 13:46
you define different interactions in different tests so there?s no reason why you can?t do what you just described

dagarwal
2018-08-15 13:49
I tried the same way .It just creates only one response for two interactions

dagarwal
2018-08-15 13:49
let me share the code with u

liran.tal
2018-08-15 13:50
you should do: 1. set up interaction 2. run your test on the cdc 3. verify the interaction for each one single test case that you have

liran.tal
2018-08-15 13:50
it?s a best practice regardless to cdc

dagarwal
2018-08-15 13:57
I have shared the code with u

matt.fellows
2018-08-15 22:31
Did you want to share it with the channel so you can get the collective help of the community?

dagarwal
2018-08-17 14:23
@matt.fellows it allows me to create only one json , m adding two interaction with diff query and same path

matt.fellows
2018-08-17 22:27
You don't need to run setup for each test. You should be able to run it once for the whole test suite. Secondly, each test is unique based on the `given` and `uponReceiving` values. You can differentiate then with different values and pact will then record them as unique interactions

uglyog
2018-08-19 02:44
has joined #pact-js


deshdeepdivakar
2018-08-19 03:17
has joined #pact-js

richarddalziel
2018-08-19 09:34
has joined #pact-js

richarddalziel
2018-08-19 09:34
Cheers!

richarddalziel
2018-08-19 09:39
If there's any examples of larger code bases with Angular Karma and PactJS out there - i'd been keen to have a look!

richarddalziel
2018-08-19 17:38
Is this usually a fairly quiet channel over the weekend yeah?

matt.fellows
2018-08-19 21:33
Hehe yeah

richarddalziel
2018-08-19 21:48
No worries :stuck_out_tongue:

matt.fellows
2018-08-19 21:51
Ah, I thought I had responded to this. I have some ideas/tips but have not used it with karma in anger.


matt.fellows
2018-08-19 21:54
The mock server that spins up is specific to each consumer/provider pair. So you can't reuse it for others. This is often the cause of strange behavior

richarddalziel
2018-08-19 21:57
The provider/consumer pair is unique. But it's specified at the top of each spec file like so : let provider; beforeAll(function (done) { provider = new PactWeb({ consumer: 'FRESUI', provider: 'FRESAPI', logLevel: 'info', port: 1234, host: 'localhost', }); // required for slower CI environments setTimeout(done, 2000); // Required if run with `singleRun: false` provider.removeInteractions(); }); afterAll(function (done) { provider.finalize().then(done, e => done.fail(e)); });

richarddalziel
2018-08-19 21:58
I had looked at the README but wasn't sure how to achieve the setup and teardown across all Karma Tests. As a sort of beforeAllTests

richarddalziel
2018-08-19 21:59
I'm not sure how much of a clue it is - but i get all sorts of failure spam on my console (Even on successful test pass).

matt.fellows
2018-08-19 22:00
I don't think you can at this point. I'd suggest setting up multiple pact servers (on different ports) in your karma config, and then link to the different servers in your tests. 1 for each mock server

richarddalziel
2018-08-19 22:05
Even with the same consumers? Is this just from a reliability standpoint?

richarddalziel
2018-08-19 22:06
It does seem to pass on occassion on the build servers, just not reliably

mboudreau
2018-08-20 04:58
most people have the weekend off from work :wink:

matt.fellows
2018-08-20 06:40
for the same consumer/provider _pair_, yes. If you have different providers but the same _consumer_ then it?s likely to cause issues

matt.fellows
2018-08-20 06:42
In your Karma config, you?ll need a separate mock server for each unique consumer/provider combination. e.g. if you have two providers, something like this: ``` // Pact Providers pact: [{ port: 1234, consumer: 'Consumer', provider: 'Provider1', log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts') }, { port: 5678, consumer: 'Consumer', provider: 'Provider2', log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts') } ], ```

matt.fellows
2018-08-20 06:44
Karma is responsible for starting the mock servers. After that, the jasmine tests are responsible for wiring to the correct mock server

richarddalziel
2018-08-20 07:22
Shock horror :joy: I only ask to set my expectations right :wink:

richarddalziel
2018-08-20 07:23
Cheers Matt - i had a quick go last night but had some issues. On for another go now :slightly_smiling_face:

richarddalziel
2018-08-20 07:36
Actually - just re-read back there. In the tests my Consumer/Provider Pair IS the same. Is it still recommended for them to be on 2 seperate providers?

matt.fellows
2018-08-20 11:32
and yet, I?m sure if we reviewed commit history this is where the majority of commits are made :smile:

mboudreau
2018-08-20 21:00
only for the good projects :wink:

matt.fellows
2018-08-20 21:01
:laughing:

richarddalziel
2018-08-21 06:25
I think i've figure out what's wrong. I had afterEach((done) => { provider.verify().then(done, e => done.fail(e)); }); In each of my tests when i was never looking to do this on my Angular tests. My intention was to create unit tests with the mock responses - generate a pact file, publish to broker and then verify the pact on the actual consumers CI Build.

richarddalziel
2018-08-21 06:26
So verifying the provider in the angular tests is pointless (Or is it, question for another day), and removing this resolves my issue

matt.fellows
2018-08-22 23:21
Hmm something doesn?t seem right here. `provider.verify().then(done, e => done.fail(e));`is not actually doing a provider verification, it?s checking that what you told the mock you were about to send to it in fact came through. If things are failing, that?s a cause for concern

matt.fellows
2018-08-22 23:22
if you could share a working example, or close enough to what you have it might be useful


richarddalziel
2018-08-23 06:31
Ah i did read afterwards that i may have misunderstood there. Perhaps there's a bug with this as it did seem to be fairly inconsistent with the results it provided. I'll hopefully get some time to dive into this again, i hit a bit of another snag with state management in the other thread too.

matt.fellows
2018-08-23 06:41
oh dear

matt.fellows
2018-08-23 06:42
if you have code that reproduces it, I can either help fix the bug, the docs or your code

richarddalziel
2018-08-23 09:00
I'll see if i can isolate it in a smaller repository - it may take me to the weekend to get round to it though

bernardo.guerreiro
2018-08-23 12:35
has joined #pact-js

bernardo.guerreiro
2018-08-23 12:48
Hello everyone. I have a question regarding using the `customProviderHeaders` . I am using it with AWS authentication, but I need each different request to be authenticated differently. How do I add a different provider header to each single interaction? Because basically, I need to dynamically add the headers according to information about the interaction I'm currently on. Is there a direct way to do this?

matt.fellows
2018-08-23 12:53
Yeah it?s a limitation at the moment. Currently you can?t do it per interaction, unless your verification step is split for each interaction (not easy to do)

matt.fellows
2018-08-23 12:53
could you please raise a request, I think I have a solution for working around how this works that could achieve this

bernardo.guerreiro
2018-08-23 13:10
i was thinking as a workaround of getting the json file from the pact broker in a separate function, running through it and dynamically adding the auth header, make a new (local json), and then use that path for the pactUrls instead. This should work right?

bernardo.guerreiro
2018-08-23 13:10
sure, where should I raise the request? pact-js repo ?

nabrosimova
2018-08-23 19:41
has joined #pact-js

bherrera
2018-08-23 19:42
has joined #pact-js

matt.fellows
2018-08-23 20:52
Yes please

bernardo.guerreiro
2018-08-24 17:01
Hello guys. I could use some help. I seem to have come across a weird bug, or maybe I am doing something wrong. We spent a while trying to debug it thinking it might be something we are doing on our side, but after debugging some of the code, I think it might be on pact-provider-verifier.rb , since I assume it is somewhere in there that it makes the HTTP request to my local server, but that's as far as we got. - I have a pact broker hosted on heroku (temporarily) deployed like this https://github.com/pact-foundation/pact_broker/tree/master/example , which i believe is using the latest version. - Since this is a Serverless project, we had to make a local server for the providerStatesSetupUrl. I am using the customProviderHeaders option to do AWS authentication. I need to pass in 3 headers. This is where it gets weird. I have to pass in 'Authorization' , 'X-Amz-Date' and 'Content-Type' headers. - If I just pass in the first 2, I can see that pact talks to my local setup server, and it passes it the state in the body of the request. This, however, won't work, since it needs the third header. - However, when I pass in the additional header 'Content-Type: application/x-www-form-urlencoded ' , for some reason, the state is no longer passed in the body of the request. It is being sent as an empty object {}, without the state. It appears if I send any Content-Type that isn't Content-Type/application-json, including some gibberish , the state gets passed as empty. Any clues?

adamgreen
2018-08-28 10:15
has joined #pact-js

adamgreen
2018-08-30 08:18
Morning all, having some issues getting Pact working with Angular 6 and Karma. See below for the log against the terminal, and the package.json file in the thread. I'm following the tutorial on the git hub page, using the Karma + Jasmine page to modify the other relavent files. Any help would be appreciated. Thank you

adamgreen
2018-08-30 08:19
apologies in advance for any rookie mistakes, first time using JS/TS frameworks here

richard.peckett
2018-08-30 08:21
has joined #pact-js

rhys
2018-09-04 10:31
has joined #pact-js

dagarwal
2018-09-04 16:08
Hello all , I am getting ?Failed to load pact from ?pacts? - Failed to parse Pact JSON - expected value at line 1 column 1 ?error after docker pull , I have not made any changes in pact file .Any suggestions ?

christophe
2018-09-19 17:25
has joined #pact-js

leon.gaban
2018-09-19 18:10
has joined #pact-js

leon.gaban
2018-09-19 18:10
Hi guys

leon.gaban
2018-09-19 18:11
I?m running into an issue and someone in general chat told me to ping you guys? https://stackoverflow.com/questions/52410277/error-with-typescript-pact-io-test-popsicleerror-unable-to-connect-to

leon.gaban
2018-09-19 18:11
Oh hah I see my issue posted above

abubics
2018-09-20 02:06
"solved" :upside_down_face:

matt.fellows
2018-09-20 12:30
Did you ever work out what this is?

matt.fellows
2018-09-20 12:31
Did you ever solve this? Sorry for my delay, must of missed it

matt.fellows
2018-09-20 12:32
I think there is an issue on the repo that logs this issue. Why do you need to _actually_ auth to AWS for the provider verification? Can you stub it out?

adamgreen
2018-09-20 13:25
hi @matt.fellows, no worries at all. Afraid I haven't been able to solve it no

dagarwal
2018-09-20 13:25
yes it worked for me later

wilson.mahann
2018-09-20 14:22
has joined #pact-js

zackary.mccolgan
2018-09-20 17:11
has joined #pact-js

matt.fellows
2018-09-20 22:42
:+1:

leon.gaban
2018-09-25 21:41
I asked this in General, but realized this is the correct place to post this issue

leon.gaban
2018-09-25 21:41
But I?m getting the following Pact test errors: ``` console.error node_modules/@pact-foundation/pact/pact.js:110 Pact verification failed! console.error node_modules/@pact-foundation/pact/pact.js:111 Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /frontoffice/api/liquidity-pool/get-total-payout ```

matt.fellows
2018-09-26 03:19
Hi @leon.gaban, the answer is in the error you are getting - your code (presumably `getTotalPayout`) is not hitting the Pact Mock Service endpoint `/frontoffice/api/liquidity-pool/get-total-payout`. It might be making an HTTP call, but it must not be calling the right thing (the Pact mock server).

leon.gaban
2018-09-26 13:12
ok I?ll work on mocking that endpoint today, thanks!

leon.gaban
2018-09-26 14:47
@matt.fellows are there any good examples you could pass on?

leon.gaban
2018-09-26 14:52
Hmm, `getTotalPayout` looks correct to me tho

leon.gaban
2018-09-26 14:53
and I have a `src/__mocks__/axios.ts` file ``` // tslint:disable-next-line:no-empty const mockNoop = () => new Promise(() => {}); export default { get: jest.fn(() => Promise.resolve({ data: { total_payout: 100.21 }})), default: mockNoop, post: mockNoop, put: mockNoop, delete: mockNoop, patch: mockNoop }; ```

leon.gaban
2018-09-26 14:56
I?ll post a new stackoverflow question (will change paths to hide real api), I need code example help at this point.


leon.gaban
2018-09-26 15:03
I will try create a small repo to reproduce this


leon.gaban
2018-09-26 15:31
running into a no tests found error atm :confused: `No tests found`

matt.fellows
2018-09-26 20:28
This suggests you're mocking out axois completely, so no http call us going to be made. Hence why it's not making any http calls to the next mock server

matt.fellows
2018-09-26 20:30
Pact is expecting a call via http. It's pretending to be your provider and will respond when interacted with

matt.fellows
2018-09-26 20:47
Thanks Leon

matt.fellows
2018-09-26 20:51
I?ve responded on Stack Overflow

matt.fellows
2018-09-26 22:44
There are multiple problems with your code 1. Axios seems to be used, but is not in your package.json. I?m guessing because you?re mocking it out (2) 2. Axios is mocked out to provide canned responses, DO NOT mock out axios during Pact testing (it?s ok for local dev if y,ou want) as this will prevent real calls being made to Pact 3. Configure axios in tests to hit the Pact mock service. Something like pactSetup.ts: ``` // Configure axios to use the Pact mock server for Pact tests import axios from "axios"; axios.defaults.baseURL = "http://localhost:1234"; ``` 4. Read the log files that Pact spits out. It tells you what?s going on. To re-iterate: You?ve told Pact that there should be an interaction on 5. You might want to use Pact for a local stub server for local development, once you?ve started generating Pacts (after 1-4 are fixed). The binary is actually installed in your node_modules and the docs for how it operates are at https://github.com/pact-foundation/pact-ruby-standalone/releases I typically have a script in package.json that looks something like: ``` "stubs": "$(find . -name pact-stub-service | head -n 1) pacts/* --port 4000" ``` So that I can run `npm run stubs` and have a local stub of the provider running on port 4000


matt.fellows
2018-09-26 22:48
The rest is up to you mate!

matt.fellows
2018-09-28 01:09
How did you go @leon.gaban?

leon.gaban
2018-09-28 13:59
I?ll try to get it working this weekend, so I?ll remove the axios mock

liran.tal
2018-09-30 08:55
while the README at `https://github.com/pact-foundation/pact-js` is for version 6, the installation instructions there are `npm i -S @pact-foundation/pact@latest` which will install version 5 since the `latest` tag is associated with that where-as 6 is tagged as pre-release

liran.tal
2018-09-30 08:55
not sure if that?s intentional or not but I find it confusing

matt.fellows
2018-09-30 11:43
That is misleading, I'll get that fixed. Thanks Liran!

liran.tal
2018-09-30 12:14
Thanks! anytime

matt.fellows
2018-09-30 21:50
:+1:

matt.fellows
2018-10-01 00:57
Fix on the way out for this process - thanks for the tip!

abubics
2018-10-01 01:48
lol, thanks integration . . . > *Release - null*

matt.fellows
2018-10-01 01:49
right?!

liran.tal
2018-10-01 11:30
Nice :)

tjones
2018-10-02 04:30
has joined #pact-js

holden.mcginnis
2018-10-03 15:45
has joined #pact-js

matt.fellows
2018-10-09 00:04
so I?m thinking of deprecating node versions below `6` in the next release. It?s hard to keep dependencies up to date and secure, because a lot of them only support 6 or later. Thoughts?

matt.fellows
2018-10-09 00:05
Release train `6.x.x` can continue to support until it?s deprecated, and `5.x.x`will be deprecated (> 1 year old now)

liran.tal
2018-10-09 00:06
@matt.fellows sounds like a good idea as 6 is anyway in maintenance mode.

liran.tal
2018-10-09 00:06
so I guess new threshold will be 8?

liran.tal
2018-10-09 00:06
5 is not relevant at all

matt.fellows
2018-10-09 00:07
I think 6 is still pretty common, so I?d prefer to start there unless good reason not to. Pact is used a lot in Enterprise environments, which can sometimes be a bit slower to upgrade/adopt

matt.fellows
2018-10-09 00:07
Part of the trigger, is I?m constantly finding myself (and others) to fix things to make it compatible - we?re fighting the system now, rather than flowing with it.

liran.tal
2018-10-09 00:09
yep that?s true

matt.fellows
2018-10-09 00:09
I can see why 8 might be good - `async` etc.

liran.tal
2018-10-09 00:09
nods

liran.tal
2018-10-09 00:10
also, 6 will be unsupported by 2019 which is just a few months ahead

matt.fellows
2018-10-09 00:10
hmmm

matt.fellows
2018-10-09 02:04
Hmmm? this integration might be a bit noisy!

mboudreau
2018-10-09 02:31
:stuck_out_tongue:

matt.fellows
2018-10-09 02:32
Was looking at some bots to automate versioning, staleness and triage issue/PRs - same :clock2:

mboudreau
2018-10-09 02:32
yeah, I just got spammed with emails

matt.fellows
2018-10-09 02:32
Heaps of good ones at https://probot.github.io/apps

mboudreau
2018-10-09 02:32
good job :wink:

matt.fellows
2018-10-09 02:32
sorry about that

dagarwal
2018-10-09 11:10
i have pact tests which have get , Put request and for video functionality .It stops working if i go higher than v0.0.9 . anyone has any idea or faced this issue


tjones
2018-10-11 00:55
Hi all - I wrote a proposal for improving the `pact-js` DSL - I'd be very interested in any thoughts: https://gist.github.com/TimothyJones/d138bf765509d41e0ce8a4bfb777a31d


adamgreen
2018-10-15 09:50
@matt.fellows hi matt, just to update you, i've managed to solve the above problem. The issue was in my *pact.spec.ts file i was trying to import Pact class from /pact instead of pact-web Using the equivalent PactWeb class is now allowing Karma to run without throwing up the errors in the previous attachement. However, when i come to try and create a broker for my tests, i'm required to use the Publisher class from pact-node module folder, doing this is bringing me back to the original problem of all those module not found errors in the terminal,. pact-web doesn't seem to have an equivalent for publishing to a broker, any ideas?

matt.fellows
2018-10-15 10:14
Hi Adam.

matt.fellows
2018-10-15 10:14
That?s great to hear! On the publishing topic, you would never want to be publishing pacts from `pact-web`, at least, it?s not an intended behaviour

matt.fellows
2018-10-15 10:15
> However, when i come to try and create a broker for my tests, Hmm, that doesn?t make sense. The broker is a hosted component (e.g. http://pact.dius.com.au or https://github.com/pact-foundation/pact_broker/), do you mean ?publish a pact?? > i?m required to use the Publisher class from pact-node module folder, doing this is bringing me back to the original problem of all those module not found errors in the terminal,. Yes, this won?t work in a non-node env (https://github.com/pact-foundation/pact-js/#using-pact-in-non-node-environments) > pact-web doesn?t seem to have an equivalent for publishing to a broker, any ideas? Yes, pact-web is just a DSL for the tests themselves, which when successfully run then produce a pact file. This is what gets published. It is recommended that only CI would publish pacts, so I would decouple the publishing (e.g. create a task `npm run pact:publish` from your test runs (`npm t`) - see https://github.com/pact-foundation/pact_broker/wiki/Set-up-checklist#consumer-team

adamgreen
2018-10-15 10:42
thanks for the reply Matt, appreciate your help. Ideally would like to debug the publishing code locally, but it could be we need to look at not using Karma if we're wanting to do that. Thanks again :+1:

matt.fellows
2018-10-15 12:08
What do you mean by "debug publishing locally"?

matt.fellows
2018-10-15 12:13
Oh right, I mean you can still test it from your local, but you wouldn't normally attach the publish step to your testing code anyway. There's an e2e example in the project repo if you want to see an example though

adamgreen
2018-10-15 12:24
we've got a http://pact.net implementation for our back end microservices, and our senior developer is setting up the entire pact test process from creation>verification>publishing as part of the test. This is allowing us to test that the broker is running the contract comparison against the consumer/provider correctly. I was attempting to do the same with our front end application (written in Angular). You think this approach is unwise in general or for simply a front-end application? Thanks

matt.fellows
2018-10-15 22:28
Just in general, you don?t want to be publishing pacts to the broker during development (i.e. TDD). Unless each time you run your test process locally you want to both publish the artifacts to the broker, and then run the provider verification (which seems very much overkill to me).

matt.fellows
2018-10-15 22:29
You might want to be able to set an environment flag (e.g. `CI=true`) to be able to test that the process works, or for setting it up in the first place

vinod.baradwaj
2018-10-16 08:25
Hi, When i try provider verification like this, ```describe('Pact Verification', () => { it('should validate the expectations of Matching Service', function () { let opts = { provider: 'Animal Profile Service', providerBaseUrl: 'http://localhost:8081', pactBrokerUrl: 'https://test.pact.dius.com.au/', pactBrokerUsername: 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', pactBrokerPassword: 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', publishVerificationResult: true, providerVersion: "1.0.0" } return new Verifier().verifyProvider(opts) .then(output => { console.log('Pact Verification Complete!') console.log(output) }); }); });``` i get an error ``` 1) Pact Verification should validate the expectations of Matching Service: TypeError: Must provide the providerBaseUrl argument at assertImpl (node_modules/check-types/src/check-types.js:730:11) at assertPredicate (node_modules/check-types/src/check-types.js:718:5) at Function.nonEmptyString (node_modules/check-types/src/check-types.js:710:14) at new Verifier (node_modules/@pact-foundation/pact-node/src/verifier.js:51:27) at Context.<anonymous> (test/pact/proververification.spec.js:26:14)```

vinod.baradwaj
2018-10-16 08:26
what am i missing in this ? i have given providerBaseUrl in opts

matt.fellows
2018-10-16 10:28
hmm it looks ok to my eye

matt.fellows
2018-10-16 10:28
Can you please share an example project on GitHub I can use to reproduce the issue? (i.e. with package.json etc.)


matt.fellows
2018-10-16 11:49
OK I think the first problem is you?re not using the `@pact-foundation/pact` dependency, albeit it should still probably work

matt.fellows
2018-10-16 11:49
see https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/provider.spec.js (it?s using a relative import, but that is the dependency from above)

matt.fellows
2018-10-16 11:52
Ah, you?re problem is you?re using the API that exists on the `@pact-foundation/pact` dependency, but calling it on the `@pact-foundation/pact-node` dependency

matt.fellows
2018-10-16 11:53
Whilst you?re passing the right options through, you?re passing them to `verifyProvider()` and not the `new Verifier(opts)` constructor. As soon as you fix the constructor problem, it will complain that the method doesn?t exist

matt.fellows
2018-10-16 11:53
TL;DR - change `const { Verifier } = require("@pact-foundation/pact-node");` to `const { Verifier } = require("@pact-foundation/pact");`

matt.fellows
2018-10-16 11:53
:ok_hand:

vinod.baradwaj
2018-10-16 12:37
thanks @matt.fellows it worked :slightly_smiling_face:

liran.tal
2018-10-16 21:45
@matt.fellows probably worth to document on the pact-foundation/pact-js github repo the different npms and what are they used for. The README on that repo also references @pact-foundation/pact-node in the broker publishing section

matt.fellows
2018-10-16 22:23
Thanks, I'll check today

daniel.straus
2018-10-16 22:38
has joined #pact-js

marco.dellolio
2018-10-16 23:06
has joined #pact-js

marco.dellolio
2018-10-16 23:07
Good evening, I?m trying to trouble shoot this request ``` describe('List of personal snippets', () => { beforeEach(() => { const interaction = { state: 'I have a list of snippets', uponReceiving: 'a request for all the snippets', withRequest: { method: 'POST', path: '/v2/searches/snippets', body: { type: 'personal' }, headers: { 'Content-Type': 'application/json', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: EXPECTED_BODY, }, } return pactProviders.scintillas.addInteraction(interaction) }) it('returns a list of snippets', async done => { const fetched_data = await fetch(`${url}/v2/searches/snippets`, { method: 'POST', body: JSON.stringify({ type: 'personal' }), headers: { 'Content-Type': 'application/json' }, }) const response = await fetched_data.json() expect(response).toEqual(EXPECTED_BODY) pactProviders.scintillas.verify() done() }) }) ``` In this setup when I added to `withRequest` ``` body: { type: 'personal' }, headers: { 'Content-Type': 'application/json', }, ``` and ``` body: JSON.stringify({ type: 'personal' }), headers: { 'Content-Type': 'application/json' }, ``` to my `fetch` request. The provider doesn?t like it and it dies right after being created ``` [2018-10-16T23:00:38.974Z] INFO: pact-node@6.19.11/72860 on Marcos-MacBook-Pro.local: Created './standalone/darwin-1.54.4/bin/pact-mock-service service --consumer 'Rhapsody' --cors 'true' --pact_dir '/Users/marcodellolio/src/rhapsody/pacts' --host '127.0.0.1' --log '/Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log' --pact-file-write-mode 'merge' --port '8001' --provider 'Scintillas' --pact_specification_version '2'' process with PID: 72882 [2018-10-16T23:00:40.051Z] INFO: pact-node@6.19.11/72860 on Marcos-MacBook-Pro.local: Removing Pact with PID: 72882 [2018-10-16T23:00:40.054Z] INFO: pact-node@6.19.11/72860 on Marcos-MacBook-Pro.local: Deleting Pact Server with options: ``` Should I parse my request in a particular way?

abubics
2018-10-17 00:14
Most of the core maintainers are at an event today, so I'm not sure when you might get a solid reply :sweat_smile:

marco.dellolio
2018-10-17 00:17
oh! thank you for letting me know, do you have a post request example I can confront mine with?

abubics
2018-10-17 00:27
I'll have a look :slightly_smiling_face:

abubics
2018-10-17 00:32
The most recent one I've got handy is from about a year ago . . .

abubics
2018-10-17 00:33
``` describe('can add an thing', () => { // given: beforeEach(() => provider.addInteraction({ state: 'a view with two samplers', uponReceiving: 'request to add a thing', withRequest: { method: 'POST', path: '/view/0/sampler/1/thing', headers: headers.request, body: { type: 'interleaved', metrics: [{ type: 'event', name: 'view' }], variants: [{ name: 'jim', data: '' }, { name: 'bob', data: '' }], name: 'Some new thing' } }, willRespondWith: { status: 201, body: { id: like('0'), state: 'unscheduled' } } }) ); // when: it('', () => client.thing .add(0, 1, { type: 'interleaved', metrics: [{ type: 'event', name: 'view' }], variants: [{ name: 'jim', data: '' }, { name: 'bob', data: '' }], name: 'Some new thing' }) .then(body => { expect(body).to.eql({ id: '0', state: 'unscheduled' }); }) .catch(fail)); }); ```

abubics
2018-10-17 00:35
and in the API client . . .

abubics
2018-10-17 00:35
well, it's quite abstracted, and using `axios`

abubics
2018-10-17 00:36
would that be useful too? or is this enough to work from?

marco.dellolio
2018-10-17 00:40
I think so thank you! I just have to figure out how correctly parse the payloads

abubics
2018-10-17 00:42
if you're not using `axios`, this may not be helpful, but here you go: ``` const mimeJson = 'application/json'; const headers = { 'Content-Type': mimeJson, Accept: mimeJson }; const GET = 'GET'; const POST = 'POST'; const PATCH = 'PATCH'; const DELETE = 'DELETE'; const transformBody = body => { if (body) { return JSON.stringify(body); } return null; }; const wrapRequest = (url, method = GET, body = null) => axios({ url, method, headers, data: transformBody(body) }) .then(resp => resp.data) .catch(error => { if (error.response) { // Made a request, but got a failure code if (error.response.data.message) { const errorMessage = { status: error.response.status, message: error.response.data.message }; throw errorMessage; } ... etc ```

marco.dellolio
2018-10-17 00:44
what `transformBody(body)` does?

abubics
2018-10-17 00:49
it's just above the `wrapRequest` function

marco.dellolio
2018-10-17 00:49
oh sorry I missed it. Thank you

abubics
2018-10-17 00:49
it just calls `JSON.stringify` if the body is truthy (mostly if it's not `null`)

matt.fellows
2018-10-17 02:56
As a quick note, to understand why it?s failing it might be worth setting logging to DEBUG and looking at the log files to see if there is any indication is to why it?s dying

matt.fellows
2018-10-17 02:56
Dying is not good :slightly_smiling_face:

marco.dellolio
2018-10-17 03:07
``` [2018-10-17T01:53:47.261Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Creating Pact Server with options: consumer = Rhapsody, cors = true, dir = /Users/marcodellolio/src/rhapsody/pacts, host = 127.0.0.1, log = /Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log, pactFileWriteMode = merge, port = 8001, provider = Scintillas, spec = 2, ssl = false, sslcert = , sslkey = [2018-10-17T01:53:47.262Z] INFO: pact@7.0.1/86087 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8001" [2018-10-17T01:53:47.815Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Starting pact binary with '/bin/sh,[object Object],... ..."NODE_ENV":"test","JEST_WORKER_ID":"1"}}' ```

marco.dellolio
2018-10-17 03:07
``` [2018-10-17T01:53:47.819Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Created './standalone/darwin-1.54.4/bin/pact-mock-service service --consumer 'Rhapsody' --cors 'true' --pact_dir '/Users/marcodellolio/src/rhapsody/pacts' --host '127.0.0.1' --log '/Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log' --pact-file-write-mode 'merge' --port '8001' --provider 'Scintillas' --pact_specification_version '2'' process with PID: 86109 [2018-10-17T01:53:48.664Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2018-10-17T01:53:48.664Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: INFO WEBrick::HTTPServer#start: pid=86109 port=8001 [2018-10-17T01:53:48.909Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Removing Pact with PID: 86109 [2018-10-17T01:53:48.911Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Deleting Pact Server with options: consumer = Rhapsody, cors = true, dir = /Users/marcodellolio/src/rhapsody/pacts, host = 127.0.0.1, log = /Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log, pactFileWriteMode = merge, port = 8001, provider = Scintillas, spec = 2, ssl = false, sslcert = , sslkey = [2018-10-17T01:53:48.913Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. FAIL test/pact/consumer/scintillas.test.js ? Test suite failed to run Error: Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout. at mapper (../../node_modules/jest-jasmine2/build/queue_runner.js:41:52) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 13.27s Ran all test suites matching /test\/pact\/consumer\/scintillas/i. ```

marco.dellolio
2018-10-17 03:09
it shuts down a second after, and obviously my fetch sends a request to not existing server

matt.fellows
2018-10-17 03:17
mmm

matt.fellows
2018-10-17 03:17
could you please try running the command it shows in the debug output? e.g. something along the lines of `./standalone/darwin-1.54.4/bin/pact-mock-service service --consumer 'Rhapsody' --cors 'true' --pact_dir '/Users/marcodellolio/src/rhapsody/pacts' --host '127.0.0.1' --log '/Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log' --pact-file-write-mode 'merge' --port '8001' --provider 'Scintillas' --pact_specification_version '2'`

matt.fellows
2018-10-17 03:18
(you probably need to ensure the args are all correct but it _should_ start a server and wait. If it crashes, that might tell us what?s happening)

matt.fellows
2018-10-17 03:18
it?s possible there is perhaps a port conflict

marco.dellolio
2018-10-17 03:29
I?m not sure what command I?m supposed to run. But as soon I remove ``` body: { type: 'personal' }, headers: { 'Content-Type': 'application/json', }, ``` from the request expectation and from the actual fetch post request, the test works correctly

matt.fellows
2018-10-17 03:33
It should start a server on port 8001

matt.fellows
2018-10-17 03:34
you should then be able to hit it e.g. `curl localhost:8001` and it should return something (an error saying it can?t find an interaction)

matt.fellows
2018-10-17 03:34
if that happens, that tells me something else is the problem

matt.fellows
2018-10-17 03:34
I?d say it?s something to do with the way your fetch thing is working

marco.dellolio
2018-10-17 03:36
I suspect that too, because I applied the headers to fix this ``` {"interaction_diffs": [{"body": {"ACTUAL": "[{\"type\":\"personal\"}]", "EXPECTED": [{"type": "personal"}]}, "description": "a request for all the snippets", "provider_state": "I have a list of snippets"}], "message": "No interaction found for POST /v2/searches/snippets"} ```

marco.dellolio
2018-10-17 03:37
because JSON.stringify(body) would not match my expected body

marco.dellolio
2018-10-17 03:37
``` withRequest: { method: 'POST', path: '/v2/searches/snippets', body: [{ type: 'personal' }], headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }, ```

marco.dellolio
2018-10-17 13:39
I was able to solve the problem using `superagent` as client for my request. Still no success with `axios` or `fetch`

brian.smith.keith
2018-10-17 14:33
has joined #pact-js

vinod.baradwaj
2018-10-17 15:10
is there an npm module for `can-i-deploy` ? (https://github.com/pact-foundation/pact_broker-client#can-i-deploy)

liran.tal
2018-10-17 23:27
I can?t spot anything odd with your fetch. are you still using superagent as a workaround?

matt.fellows
2018-10-17 23:30
Yeah, it looks ok to me.

matt.fellows
2018-10-17 23:31
Marco if you could please create a small project we can use to repro and raise an issue on pact-js, we?ll get to the bottom of it.

marco.dellolio
2018-10-18 00:31
Update, looks like I was doing something odd with the beforeAll, afterAll hooks in Jest. I?m trying to spin up a mock provider for each service ``` global.pactProviders = { scintillas: new Pact({ port: 8000 + Number(process.env.JEST_WORKER_ID), log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), } ```

marco.dellolio
2018-10-18 00:33
Looks like is working now, I?ll try to replace `superagent` with `fetch`

matt.fellows
2018-10-18 04:48
:thumbsup:

marco.dellolio
2018-10-19 01:08
Good evening again. Do you mind clarifying this(?): >Each test is fully self-contained, with its own mock server on its own port for ?test? it means test suit I guess. I?m trying to start those 2 providers in parallel ``` global.pactProviders = { scintillas: new Pact({ port: 8000 + Number(process.env.JEST_WORKER_ID), log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), emailGateway: new Pact({ port: 8000 + Number(process.env.JEST_WORKER_ID), log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), } ``` with a ``` beforeAll(async done => { await pactProviders.scintillas/emailGateway.setup() done() }) ``` in each suit but it errors with `Port '8001'/'8002' is already in use by another process.` Working correctly if remove one provider from the global object. Thank you in advance

mboudreau
2018-10-19 01:11
It can be for each test, but it normally adds extra overhead to restart the server every time

mboudreau
2018-10-19 01:12
but fomr what I can see, the JEST_WORKER_ID would be the same for both mocks

mboudreau
2018-10-19 01:12
hence it would have a port conflict

marco.dellolio
2018-10-19 01:13
Shouldn?t the `JEST_WORKER_ID` increase with the test suit ran?

marco.dellolio
2018-10-19 01:15
in fact is failing on two different ports ``` ime: 1s, estimated 4s FAIL test/pact/consumer/email_gateway.test.js0-19T01:07:30.248Z] INFO: pact@7.0.1/96160 on Marcos-MacBook-Pro.local: ? Test suite failed to run Port '8001' is already in use by another process. 16 | logLevel: 'error', 17 | }), > 18 | emailGateway: new Pact({ | ^ 19 | port: 8000 + Number(process.env.JEST_WORKER_ID), 20 | log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), 21 | dir: path.resolve(process.cwd(), 'pacts'), at Pact.Object.<anonymous>.Pact.createServer (../../node_modules/@pact-foundation/pact-node/src/pact.ts:48:10) at new Pact (../../node_modules/@pact-foundation/src/pact.ts:64:34) at Object.<anonymous> (testSetup.js:18:17) FAIL test/pact/consumer/scintillas.test.js ? Test suite failed to run Port '8002' is already in use by another process. 16 | logLevel: 'error', 17 | }), > 18 | emailGateway: new Pact({ | ^ 19 | port: 8000 + Number(process.env.JEST_WORKER_ID), 20 | log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), 21 | dir: path.resolve(process.cwd(), 'pacts'), at Pact.Object.<anonymous>.Pact.createServer (../../node_modules/@pact-foundation/pact-node/src/pact.ts:48:10) at new Pact (../../node_modules/@pact-foundation/src/pact.ts:64:34) at Object.<anonymous> (testSetup.js:18:17) Test Suites: 2 failed, 2 total Tests: 0 total Snapshots: 0 total Time: 2.156s, estimated 4s Ran all test suites matching /test\/pact\/consumer/i ```

marco.dellolio
2018-10-19 01:28
I believe the problem could be in the `beforeAll`: before running the 1st test it starts 8001. Because the suit haven?t started yet and the ?reserved the worker 1? it tries to start a new provider again on 8001.

matt.fellows
2018-10-19 01:59
Have you seen the Jest example in the pact-js repo?

marco.dellolio
2018-10-19 02:00
yes, but in that example there is a single provider

matt.fellows
2018-10-19 02:00
yes, but it is used across two separate test suites

matt.fellows
2018-10-19 02:00
in your case above, technically it _is_ just a single provider ?Scintillas?

matt.fellows
2018-10-19 02:00
You?re just creating two instances of it

matt.fellows
2018-10-19 02:02
In any case, I think you?re right about the logic.

marco.dellolio
2018-10-19 02:02
Hi Matt, this what I?m trying to avoid. If I?m not wrong the example should be run with `--runInBand`

matt.fellows
2018-10-19 02:02
true, yes

marco.dellolio
2018-10-19 02:02
I?m trying to start in parallel two different providers

matt.fellows
2018-10-19 02:02
np

matt.fellows
2018-10-19 02:03
(just wanted to make sure you had good reasons and had thought about it first :slightly_smiling_face: )

matt.fellows
2018-10-19 02:04
I think you?re right though, it?s probably a logic thing where the provider is being created too many times

marco.dellolio
2018-10-19 02:05
I need, in someway, to bind the the second provider to the starting on the first test suit

marco.dellolio
2018-10-19 02:06
or I could scope the `beforeAll` inside each test suit, making sure to start only when the previous is started

matt.fellows
2018-10-19 02:08
why not just a) hard code the port for each test suite or b) randomly generate the port for each test suite?

matt.fellows
2018-10-19 02:08
`s/test/test suite`

marco.dellolio
2018-10-19 02:18
well, hard coding the ports, brought up something new. ``` Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8001" [2018-10-19T02:16:38.270Z] INFO: pact@7.0.1/1710 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8002" ```

marco.dellolio
2018-10-19 02:19
do you see anything wrong with this global object pattern? ``` global.pactProviders = { scintillas: new Pact({ port: 8001, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), emailGateway: new Pact({ port: 8002, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), } ```

mboudreau
2018-10-19 02:24
seems to work fine when hard coding?

mboudreau
2018-10-19 02:25
could it be at jest uses parallel test runners?

mboudreau
2018-10-19 02:25
I'm not entirely versed in how jest works

matt.fellows
2018-10-19 02:25
looks OK to me

marco.dellolio
2018-10-19 02:34
sometimes javascript is frustrating ``` Test Suites: 0 of 2 total Tests: 0 total Snapshots: 0 total Time: 1s[2018-10-19T02:36:27.226Z] INFO: pact@7.0.1/5567 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8001" [2018-10-19T02:36:27.228Z] INFO: pact@7.0.1/5567 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8002" [2018-10-19T02:36:27.273Z] INFO: pact@7.0.1/5568 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" RUNS test/pact/consumer/scintillas.test.js RUNS test/pact/consumer/email_gateway.test.js Test Suites: 0 of 2 total Tests: 0 total Snapshots: 0 total Time: 2s[2018-10-19T02:36:27.933Z] ERROR: pact-node@6.19.11/5568 on Marcos-MacBook-Pro.local: Pact Binary Error: /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) for "127.0.0.1" port 8001 (Errno::EADDRINUSE) from /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in `new' from /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in `block in create_listeners' from /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:82:in `each' ```

marco.dellolio
2018-10-19 02:34
now fails on the same port

mboudreau
2018-10-19 02:35
I don't see a failure?

marco.dellolio
2018-10-19 02:37
sorry I should have it past it all

mboudreau
2018-10-19 02:40
right, I believe it's because that jest try to run all tests in parallel

mboudreau
2018-10-19 02:40
hence, there will be a port conflict

mboudreau
2018-10-19 02:40
unless, there's an individual pact server ran on a random port

mboudreau
2018-10-19 02:40
for each test

marco.dellolio
2018-10-19 02:42
I?m trying to achieve parallelism. For what concerns the server setup I?m just using the following ``` beforeAll(done => { Promise.all( Object.keys(pactProviders).map(provider => pactProviders[provider].setup()) ).then(() => done()) }) afterAll(done => { Promise.all( Object.keys(pactProviders).map(provider => pactProviders[provider].finalize() ) ).then(() => done()) }) ```

mboudreau
2018-10-19 02:43
instead of using beforeAll/afterAll

mboudreau
2018-10-19 02:43
why don't you just use a single before/after?

mboudreau
2018-10-19 02:43
which will run before and after each individual tests?

marco.dellolio
2018-10-19 02:44
I should set a specific before hook for each test suit?

mboudreau
2018-10-19 02:47
I think so, if you want to go the parallel route :slightly_smiling_face:

marco.dellolio
2018-10-19 02:51
let me try this path and I?ll let you know. Thank you guys!

mboudreau
2018-10-19 02:52
:thumbsup:

abubics
2018-10-19 03:26
Btw, we're aware that this is a frustrating issue (especially with Jest), and @schalkt worked on a proposal for a better DSL: https://github.com/pact-foundation/pact-js/issues/215

marco.dellolio
2018-10-19 03:33
so, I was able to run the test in parallel defining the provider inside the test suit. Thank you all as always and good night

abubics
2018-10-19 03:34
Where are you, Marco? It's only 14:34 here :sweat_smile:

marco.dellolio
2018-10-19 03:35
Atlanta, US. Its 23:35 here!

marco.dellolio
2018-10-19 03:35
Where are you all?

abubics
2018-10-19 03:40
Many of us are in Melbourne, Australia~* :flag-au:

mboudreau
2018-10-19 04:07
:arrow_up:

abubics
2018-10-19 04:08
Haha, many are in other places, too :stuck_out_tongue:

tjones
2018-10-22 03:06
@matt.fellows (and other interested parties) - I'm thinking of closing all of those dependabot pull requests

tjones
2018-10-22 03:07
Many of them introduce breaking changes, and for the ones that don't, I'm not sure we should be upgrading libraries without a reason

tjones
2018-10-22 03:07
Thoughts?

matt.fellows
2018-10-22 04:02
yep, go for it. There?s that branch for pact-js that we?ll fix manually to begin with, at which point we can re-enable it

abubics
2018-10-22 04:11
lol, looks like Github's coming back online

simon.nizov
2018-10-23 10:11
@simon.nizov has left the channel

marco.dellolio
2018-10-23 13:11
Hey Guys good morning (I guess good evening in AU:flag-au:). Thank you for your help with jest, everything is running smoothly! I have a question about Karma

marco.dellolio
2018-10-23 13:13
I define my pact server in `karma.conf.js` and in the test file I create a new provider. ``` provider = new Pact.PactWeb({ consumer: 'Rhapsody', provider: 'Scintillas', port: 9443, host: '127.0.0.1', }) ``` What if in my `karma.conf.js` I define more servers, how do I create a mock provider identifying the right server? Just the port?

tom.hombergs
2018-10-23 19:39
has joined #pact-js

tom.hombergs
2018-10-23 19:40
@marco.dellolio yes, we use it like that. The only difference is the port (and potentially the provider name)

matt.fellows
2018-10-23 20:57
@marco.dellolio, as @tom.hombergs said. You also don?t even need to pass the consumer/provider to the `PactWeb` constructor anymore (no need to duplicate what?s configured in the karma conf anyway). There should be a warning in your console about that I think

marco.dellolio
2018-10-23 21:04
Thank you guys. Yes I was able to dry up my code a little

matt.fellows
2018-10-23 21:18
:+1:

marco.dellolio
2018-10-24 02:14
Hello guys, does anybody have a good use case of Pact working with `$httpBackend` in Angular.js sounds like it prevents to make real http request in the test environment


matt.fellows
2018-10-24 02:32
That?s a pretty old repo, but the idea is probably the same - you?ll need to ensure there is a real http service injected into your configuration

matt.fellows
2018-10-24 02:32
I haven?t used Angular for a few years, and am out of touch with current practices myself

marco.dellolio
2018-10-24 03:00
For me is brand new, we have a good part of our legacy front end with Angular models serving data to React Components, need to cover those with Pact as well

tom.hombergs
2018-10-24 03:20
@matt.fellows thanks for looking into https://github.com/pact-foundation/pact-js/issues/234 for me! What's the difference between the @pact-foundation/pact-web and @pact-foundation/pact packages anyways?

matt.fellows
2018-10-24 04:05
No worries @tom.hombergs. I don?t have time for the longer version, but the TL;DR is https://github.com/pact-foundation/pact-js/#using-pact-in-non-node-environments

abubics
2018-10-26 05:00
new project, who dis? ``` .../node_modules/@pact-foundation/pact/pact.js:40 this.opts = Pact.createOptionsWithDefaults(config); ^ TypeError: Cannot set property 'opts' of undefined ```

abubics
2018-10-26 05:01
Anyone seen this coming from the `Pact({...})` provider constructor?


abubics
2018-10-26 05:05
ahaha omg . . . missing a `new` keyword :ok_hand::innocent:

matt.fellows
2018-10-26 06:34
Lol

matt.fellows
2018-10-27 05:23
Thanks @tom.hombergs

matt.fellows
2018-10-27 05:23
also, in case you haven?t seen it, your eyeballs on https://github.com/pact-foundation/pact-js/issues/209 and https://github.com/pact-foundation/pact-js/issues/215 would be appreciated. Looking to simplify things whilst also making it more powerful/expressive

mmonson
2018-10-30 20:07
has joined #pact-js

anothonyvong
2018-11-01 21:37
has joined #pact-js

hansrd_98
2018-11-02 01:42
has joined #pact-js

romuald.quantin
2018-11-02 08:12
has joined #pact-js

jeffm
2018-11-02 22:41
has joined #pact-js

jjlehva
2018-11-03 12:37
has joined #pact-js

liran.tal
2018-11-05 12:47
yay

liran.tal
2018-11-05 12:47
mostly passed :slightly_smiling_face:

nic
2018-11-06 09:04
has joined #pact-js

rjmcguinness
2018-11-20 16:00
has joined #pact-js

rjmcguinness
2018-11-20 16:29
Hi everyone. Is the intention of the function in this example https://github.com/pact-foundation/pact-js/blob/d8214e6112f3ba26b93f46bee7fa6f3d8d970f76/karma/jasmine/client.js#L8 to show that we need to implement a method in each service we test with pact to override the environment's api base url? Thanks for any advice you can give

rjmcguinness
2018-11-20 17:06
The below code passes when calling `apiService.createPactClient`. I'd prefer not to have to create a new method in this service just to set localhost as the base url instead of the environment's api base url. However if I try to hardcode the base url + my path in the `karma.conf.js` as proxy key, it can't see the request. Am I doing something wrong? Using Angular 6 + Karma + Jasmine ``` // karma.conf.js module.exports = function (config) { ... pact: [{ consumer: 'ApiService', provider: 'backend', port: 7228, logLevel: 'DEBUG', cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), }], proxies: { '/me': 'http://127.0.0.1:7228/me', }, } ``` ``` // api.service.js import environment from './environment'; // simplified from a Typescript + Angular 6 class class ApiService { // Overwrite the environment base api url createPactClient(baseUrl: string) { environment.apiBaseUrl = baseUrl; } getUser() { const path = '/me'; return HttpClient.get(`${environment.apiBaseUrl}${path}`, new HttpHeaders()); } } ``` ``` // api.service.spec.js import * as Pact from '@pact-foundation/pact-web'; describe('PACT ApiService', () => { let apiService; let provider; const dummyUser = { firstName: 'dummy firstName', lastName: 'dummy lastName', }; beforeAll(done => { provider = new Pact.PactWeb({ port: 7228, host: '127.0.0.1', }); done(); provider.removeInteractions(); // Required for `singleRun: false` }); afterAll(done => { provider.finalize().then(done, e => done.fail(e)); }); beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientModule], providers: [ApiService], }); apiService = TestBed.get(ApiService); }); describe('getUser', () => { beforeAll(done => { provider.addInteraction({ state: 'provider responds with a user', uponReceiving: 'a request to GET a user', withRequest: { method: 'GET', path: `/me`, }, willRespondWith: { status: 200, body: Pact.Matchers.somethingLike(dummyUser), }, }).then(done, e => done.fail(e)); }); afterEach(done => { provider.verify().then(done, e => done.fail(e)); }); it('should get user', done => { // Overwrite the environment api base url apiService.createPactClient('http://localhost:7228'); apiService.getUser().subscribe(response => { expect(response).toEqual(dummyUser); done(); }, e => done.fail(e)); }); }); }); ```

matt.fellows
2018-11-21 05:11
Pretty much, yes. Another standard option is to use Environment variables to inject configuration (in non-Karma use cases probably)

matt.fellows
2018-11-21 05:16
I?m not that familiar with `proxies` in Karma/Angular. Is it possible to have another `environment` configuration for `pact` tests, which contains the endpoint/port required for pact tests? This way it?s consistent with the rest of your code base?

rjmcguinness
2018-11-21 09:23
Thanks I will try to set up another environment for pact, but instead I think it would be for karma as that is what I use to run pact along with my other tests. Perhaps having them run independently makes more sense. I'll work out how to set the environment variable for the base url to localhost when running in karma + pact

borsuk.artem034
2018-11-21 15:35
has joined #pact-js

bernardo.guerreiro
2018-11-23 15:11
Hey everyone. I was wondering if people have had experience using this in integration between frontend and backend (for example a React app and a NodeJS backend)? The reason I'm asking is because I am now working on establishing it between frontend and backend (where I see it can definitely bring a lot of value), but I feel like the "Consumer Driven" part gets a bit lost in some parts, depending on how you do it. I saw a couple of examples of people trying it online, and I guess that's what I want to know - what you think is the best approach: - Approach A: you write your consumer tests on the http client or functions dealing with making the requests, and you just concern yourself with the data being handled properly by the HTTP client; - Approach B: you write actual frontend facing consumer tests on how this data is handled by the UI; So, Approach A is simple to implement and still guarantees that when the provider API makes changes, it doesn't break the frontend (the more common use-case). But Approach B is more "consumer driven" , because if you were to make changes to how you handle or expect the data, it would actually break a consumer build. Which one is best? Is there value in both?

liran.tal
2018-11-23 21:13
@bernardo.guerreiro happy you?re bringing up the subject. A sounds more like by-the-book consumer unit testing. B you can still do but in a form of end-to-end integration tests. Meaning that with B you are actually clicking buttons on the UI and driving flows that trigger API calls, which you can then have a stubbed mock server based on the consumer contracts, to return the results for.

matt.fellows
2018-11-24 15:57
I think b, but not in the form that tests via a UI e2e test. You want to test your service delegate code / collaborator. If it still feels closer to a pure unit test then you're in the sweet spot

matt.fellows
2018-11-24 15:58
Most examples use the http client for convenience/ simplicity

matt.fellows
2018-11-24 15:58
See js issues - one is there about expired being contrived

dagarwal
2018-11-26 12:10
Hey Guys , I am writing a provider verification tests and verification is failing due to difference in actual and expected .I am trying to add matchers and see if it works .I am using method verifyProvider and for that i was used the parameter pactBrokerUrl .I want to know is it possible to verify the provider with my local json file and if yes , how ?

liran.tal
2018-11-26 12:17
@dagarwal sure, you can `pactUrls` instead of `pactBrokerUrl` and include contract files from the local filesystem. an example from the docs: ```js pactUrls: [path.resolve(process.cwd(), "pacts", "myjsmessageconsumer-myjsmessageprovider.json")], ```

dagarwal
2018-11-26 12:17
Wow cool thanks :slightly_smiling_face:

liran.tal
2018-11-26 12:17
:+1:

dagarwal
2018-11-26 12:18
~I am gettign * Expected 8061159 but got 15053699 at $[0].id * Expected ?Country? but got ?address? at $[0].name * Expected ?Country? but got ?Address? at $[0].displayName * Actual array is too short and should have contained 10329 at $[0].visibilityIds[1] * Actual array is too short and should have contained 10323 at $[0].visibilityIds[2] * Actual array is too short and should have contained 10240 at $[0].visibilityIds[3] * Actual array is too short and should have contained 17575 at $[0].visibilityIds[4] * Expected ?31 Jan 2018 11:56:48 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].created * Expected ?01 Feb 2018 11:58:49 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].lastModified * Expected 8078165 but got 15053796 at $[1].id * Expected ?demo-tt? but got ?asdf? at $[1].name * Expected ?Demo tt? but got ?asdf? at $[1].displayName * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].created * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].lastModified * Actual array is too long and should not contain a Hash at $[2] * Actual array is too long and should not contain a Hash at $[3] * Actual array is too long and should not contain a Hash at $[4] * Actual array is too long and should not contain a Hash at $[5] * Actual array is too long and should not contain a Hash at $[6] * Actual array is too long and should not contain a Hash at $[7] and so on when i am doing provider verification~

dagarwal
2018-11-26 12:19
I am getting * Expected 8061159 but got 15053699 at $[0].id * Expected ?Country? but got ?address? at $[0].name * Expected ?Country? but got ?Address? at $[0].displayName * Actual array is too short and should have contained 10329 at $[0].visibilityIds[1] * Actual array is too short and should have contained 10323 at $[0].visibilityIds[2] * Actual array is too short and should have contained 10240 at $[0].visibilityIds[3] * Actual array is too short and should have contained 17575 at $[0].visibilityIds[4] * Expected ?31 Jan 2018 11:56:48 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].created * Expected ?01 Feb 2018 11:58:49 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].lastModified * Expected 8078165 but got 15053796 at $[1].id * Expected ?demo-tt? but got ?asdf? at $[1].name * Expected ?Demo tt? but got ?asdf? at $[1].displayName * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].created * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].lastModified * Actual array is too long and should not contain a Hash at $[2] * Actual array is too long and should not contain a Hash at $[3] * Actual array is too long and should not contain a Hash at $[4] * Actual array is too long and should not contain a Hash at $[5] * Actual array is too long and should not contain a Hash at $[6] * Actual array is too long and should not contain a Hash at $[7] and so on when i am doing provider verification.Even if i add PACT.like it starts to give ?visibilityIds?: [ ... , - Fixnum, - Fixnum, - Fixnum, - Fixnum, + Pact::IndexNotFound, + Pact::IndexNotFound, + Pact::IndexNotFound, + Pact::IndexNotFound, ] }, ... , - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex,

dagarwal
2018-11-26 12:19
Can someone help me with what kind of matchers needs to be added

syed.haq
2018-11-26 14:20
has joined #pact-js

matt.fellows
2018-11-26 16:56
What have you tried? Can you please share? Looks like you need an `eachLike`

dagarwal
2018-11-26 16:56
i tried like

dagarwal
2018-11-26 16:59
will try with each like .Basically provider have big array list like { (arr1,val1), (arr2,val2) , (arr3,val3) and so on and I have added just two values {(arrConsumer1,valConsumer1) ,(arrConsumer2,valConsumer2) )

dagarwal
2018-11-26 16:59
Also values are different

dagarwal
2018-11-27 10:19
Hi , I am getting this error after adding matchers : like while doing verification . 1) Verifying a pact between flex-search-app and flex-taxonomy-service Get object for listing taxonomies with GET /api/taxonomies?accountId=4&enabled=true returns a response which has a matching body Failure/Error: expect(response_body).to match_term expected_response_body, diff_options, example [2018-11-27T10:14:07.150Z] WARN: pact-node@6.20.0/41092 on Dollys-MacBook-Pro.local: Pact exited with code 1. Actual: [{?id?:15053699,?name?:?address?,?displayName?:?Address?,?description?:??,?enabled?:true,?accountId?:4,?visibilityIds?:[4],?userId?:5,?created?:?10 Jul 2018 11:04:50 +00:00?,?lastModified?:?10 Jul 2018 11:04:50 +00:00?},{?id?:15053796,?name?:?asdf?,?displayName?:?asdf?,?description?:??,?enabled?:true,?accountId?:4,?visibilityIds?:[4],?userId?:5,?created?:?10 Jul 2018 11:21:20 +00:00",?lastModified?:?10 Jul 2018 11:21:20 +00:00"}, and so on Its a huge array list at provider level . At At consumer level i have added the test as : before(() => { return provider.addInteraction({ given: ?GET call for taxonomies?, uponReceiving: ?Get object for listing taxonomies?, withRequest: { method: ?GET?, path: ?/api/taxonomies?, query: { accountId: term({ generate: ?4?, matcher: ?4? }), enabled: term({ generate: ?true?, matcher: ?true? }) } }, willRespondWith: { status: 200, body: [ like ({ ?id?: like(8061159), ?name?: like(?Country?), ?displayName?: like(?Country?), ?description?: like(??), ?enabled?: like(true), ?accountId?: like(4), ?visibilityIds?: like([ 4, 10329, 10323, 10240, 17575 ]), ?userId?: like(5), ?created?: like(?31 Jan 2018 11:56:48 +00:00?), ?lastModified?: like(?01 Feb 2018 11:58:49 +00:00?) }) ] } }); });

liran.tal
2018-11-27 10:24
@dagarwal it?s really hard to help with partial output. if you don?t have the code publicly available to look at, can you paste the full output of the pact test failure on some place like pastebin and provide a link?

dagarwal
2018-11-27 10:24
Ok sure would do that




liran.tal
2018-11-27 10:38
I can point out several things that look a bit off. on the consumer side - 1. the term matchers on the query doesn?t look like they?re used properly. the matcher is supposed to be a regex syntax 2. the matching for dates is not going to really work the way you think, it?ll just match any string type, not the actual date format you see there now. 3. the visibility ids are using hard coded items

dagarwal
2018-11-27 10:39
cool , let me try updating these and see if it works Thanks !!

liran.tal
2018-11-27 10:39
I suggest that you try to build the contract and verify it step-by-step. it will be easier for you to debug what?s wrong and why it fails

liran.tal
2018-11-27 10:40
if you add many matchers and expectations on the consumer side and something fails on the provider, it?s hard to debug why exactly.

liran.tal
2018-11-27 10:40
I mean, the log is there to help you but if you?re starting out fresh you might want to take it in steps

dagarwal
2018-11-27 10:41
Actually we built in huge tests at consumer level and data has got complex .now we are doing provider verification :disappointed: should have done it from initial stage .I am really struggling now

matt.fellows
2018-11-27 17:46
I can see the problem

matt.fellows
2018-11-27 17:46
when using array matchers, you need to remove the actual array within/ouotside

matt.fellows
2018-11-27 17:46
e.g.

matt.fellows
2018-11-27 17:47
`body: eachLike({?})` not `body: [ like({...}) ]`

matt.fellows
2018-11-27 17:47
or `body: eachLike({?})` not `body: eachLike([{...}])`

matt.fellows
2018-11-27 17:47
`eachLike` implies it?s an array

matt.fellows
2018-11-27 17:48
so pact is expecting an array containing an array

matt.fellows
2018-11-27 17:53
I?ve answered your question on SO also

dagarwal
2018-11-28 08:36
Thanks a lot :dancer: it worked

rjmcguinness
2018-11-28 17:01
Hi, Are there are any recommended ways to automate pact test creation (in my case for an Angular 7 webapp)? Preferably generating tests off an (api) service


rjmcguinness
2018-11-28 17:31
Thanks. We have an api service which is rapidly expanding and are looking for a sustainable way to expand our pact tests without copy and pasting chunks of `describe('...` Really trying to decide where the source of truth is, and how to minimise mistakes in the pact tests

matt.fellows
2018-11-28 17:32
gotcha

matt.fellows
2018-11-28 17:33
great!

matt.fellows
2018-11-28 17:34
Don?t forget to accept the answer :wink:

matt.fellows
2018-11-28 17:35
The key thing is that each test needs to capture the intentions of the consumer, not what is documented in a provider.

matt.fellows
2018-11-28 17:37
It might be possible to automate it, but you?re likely to add in assumptions that your client code is doing that may be incorrect and therefore void all of the pact work

rjmcguinness
2018-11-29 09:22
Understood. Thanks. I think we won't be automating this now.

matt.fellows
2018-11-29 16:38
@dagarwal can you please share what you expect your API response to look like to help you with your matchers?

matt.fellows
2018-11-29 16:39
I suspect you want an object which contains array items (taxon's), not an array of items which always have arrays nested within

matt.fellows
2018-11-29 16:39
This is why it's telling you it's expecting an array, but got a hash

matt.fellows
2018-11-29 16:41
The eachLike matcher says at the location specified, it expects an array

kamilmarkow
2018-11-29 16:57
has joined #pact-js

dagarwal
2018-12-03 09:07
@matt.fellows Yes exactly . It contains array items in taxons . Please find link : https://pastebin.com/2SJnTrfG

matt.fellows
2018-12-03 10:01
So if the root reflect is not an array, reminder the eachlike matcher on it, but leave it for taxons

sai.krishna
2018-12-03 14:34
has joined #pact-js

dagarwal
2018-12-03 15:11
reminder the eachlike matcher on it, means .I dint get it :disappointed:

matt.fellows
2018-12-03 21:18
I?ve updated the example in SO. I think you want this: ``` const firstChild = like({ ?name?: ?Geo?, ?taxons?: eachLike({ ?id?: 115590, ?name?: ?Africa?, ?hasChildren?: false }) }); `` Note that the initial `eachLike` is now just `like`. This means you don?t expect an array at the root of the response, you want an object.

nic
2018-12-04 12:28
~hey pact people, has anyone got an example of updating the provider on a test by test basis for jest? my consumer has contracts with multiple providers so I need to update the provider on a test by test basis to create multiple pacts. I don't think I've seen an example of doing this in JS - i might have missed it. any pointers gratefully received!~

dagarwal
2018-12-04 14:34
Thanks @matt.fellows :slightly_smiling_face:

dagarwal
2018-12-04 14:34
i want to use more than one element in array. I am using eachLike with min .Can you guys tell me whats wrong here : const taxonomiesList = [{ ?id?: 8061159, ?name?: ?Country?, ?displayName?: ?Country?, ?description?: ??, ?enabled?: true, ?accountId?: 4, ?visibilityIds?: like[4], ?userId?: 5, ?created?: ?31 Jan 2018 11:56:48 +00:00?, ?lastModified?: ?01 Feb 2018 11:58:49 +00:00? }, { ?id?: 8078165, ?name?: ?demo-tt?, ?displayName?: ?Demo tt?, ?description?: ??, ?enabled?: true, ?accountId?: 4, ?visibilityIds?: like[4], ?userId?: 5, ?created?: ?01 Feb 2018 11:03:59 +00:00?, ?lastModified?: ?01 Feb 2018 11:03:59 +00:00? ]) const taxonomies = eachLike(taxonomiesList, { min: 2}); module.exports = { taxonomies }; But this is generating both id ( inside body ) two times ( so total 4) in the json file

matt.fellows
2018-12-04 20:25
All good. Did that help you understand how it works?

yousafn
2018-12-04 22:06
has joined #pact-js

dagarwal
2018-12-05 08:31
yes but still I am unable to create data for more than one element in array using eachLike and min

matt.fellows
2018-12-05 10:51
If you need further help, we'll need a code base where we can reproduce the problem your having exactly

dagarwal
2018-12-05 11:28
Okay

matt.fellows
2018-12-05 19:08
Thanks

matt.fellows
2018-12-06 23:05
@dagarwal I?ve mentioned this a few times - _do not_ put an array `[]` inside of the `eachLike` statement for what you are trying to do to. It is trying to create a multi-dimensional array. You want a single dimension array, so simply put _one_ object inside the `eachLike` clause e.g. ``` eachLike({ 'id': 8061159, 'name': 'Country', 'displayName': 'Country', 'description': '', 'enabled': true, 'accountId': 4, 'visibilityIds': like[4], 'userId': 5, 'created': '31 Jan 2018 11:56:48 +00:00', 'lastModified': '01 Feb 2018 11:58:49 +00:00' }) ```

rjmcguinness
2018-12-12 10:09
Hi Matt and all, Could you explain this setTimeout to me please? https://github.com/pact-foundation/pact-js/blob/master/karma/jasmine/client-spec.js#L16 I had intermittently failing tests yesterday (only in our CI build - in docker on VSTS, and very occasionally locally) and putting `done()` into the setTimeout in that beforeAll for each test fixed it. Still can?t work out which interaction clearing this is delaying. Is this preventing tests from clearing each other?s interactions? Or is it preventing one of the below lines from clearing the test?s own interactions before the request is received? `provider.removeInteractions();` `provider.finalize().then(done, e => done.fail(e));` `provider.verify().then(done, e => done.fail(e));` In this failing test we can see the interaction was registered, then cleared and then request was received (so no request was found). ``` I, [2018-12-11T16:32:35.619070 #5595] INFO -- : Registered expected interaction GET /my/stuff D, [2018-12-11T16:32:35.619242 #5595] DEBUG -- : { "description": "a request to GET stuff", "providerState": "provider responds with snapshot ref data", "request": { "method": "GET", "path": "/my/stuff" }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "json_class": "Pact::SomethingLike", "contents": { "0": { "stuff": "dummy stuff", } } } } } I, [2018-12-11T16:32:35.620329 #5595] INFO -- : Cleared interactions I, [2018-12-11T16:32:35.653797 #5595] INFO -- : Received request GET /my/stuff ```

rjmcguinness
2018-12-12 10:40
? then this line triggers the fail ``` E, [2018-12-11T16:32:35.653947 #5595] ERROR -- : No matching interaction found for GET /my/rates-evidence ```

dagarwal
2018-12-12 11:51
yes @matt.fellows thanks

matt.fellows
2018-12-12 20:51
It's a bit of a hack. Its basically saying "wait for 2 seconds and hope the pact mock server is up in time on port 1234

matt.fellows
2018-12-12 20:51
A better way would be to wait for the port to be ready

matt.fellows
2018-12-12 20:51
Is this test failing or one of yours? If you share the code I'm happy to take a look

rjmcguinness
2018-12-13 09:25
I had random failures on my CI build only across all tests until I put the done in a setTimeout. All tests are consistently passing now, but adds +2s for each test. What I?m trying to understand is which line is doing the ?Cleared interactions? in between registering interaction and receiving request. From looking at pact-web.js, could be one of three provider methods (mentioned above). Line 28, 32 or 70 in below gist. Here?s the gist, thanks :slightly_smiling_face: https://gist.github.com/rorymcgit/819f1a3eb697c864fcf47c9e6f8f5fe2

matt.fellows
2018-12-13 09:29
removeInteractions, finalise and verify will all clear them from memory

rjmcguinness
2018-12-13 09:44
Do you know which one of these is causing the ?Cleared interactions? in this case, i.e. if the `done()` on line 25 is not in a setTimeout?

matt.fellows
2018-12-13 11:29
hmm not at a cursory glance i?m sorry. If you had your code to share i?m haappy to look at that too


matt.fellows
2018-12-13 20:37
Hmm the provider removeInteractions in the before all is a promise. Stricly speaking you might want to properly handle it even tho the setTimeout above should prevent it.

matt.fellows
2018-12-13 20:37
Are there any strange Jasmine overlapping behaviours causing strangeness?

rjmcguinness
2018-12-14 10:51
I found that everything ran in the order it should have run (by putting a load of numbered console.logs throughout the code), even for failing tests. That?s interesting that `removeInteractions` isn?t really being handled properly. I might try moving the done from inside the setTimeout to in a `.then`. Thanks for your help - I?ll update you if I find anything interesting

rjmcguinness
2018-12-19 10:08
@matt.fellows I said I?d update if I found anything interesting, and I think I have. https://gist.github.com/rorymcgit/cf7cc8f07c20507f699900f8484435c1#file-api-service-get-foo-pact_v2-spec-ts-L23 Moving the `done()` to happen on resolve of the `removeInteractions` means my CI build does not have pact tests failing intermittently (like it was without being wrapped by the setTimeout) and does not add 2 seconds per test either.

matt.fellows
2018-12-19 23:31
Thanks @rjmcguinness - makes sense!

davegallant
2019-01-02 17:18
has joined #pact-js

dagarwal
2019-01-02 17:28
Hello , Do we have any npm package to install can-i-deploy ?

mboudreau
2019-01-02 23:11
Sorry, I haven't gotten around to enabling that in pact-node yet :confused:

dagarwal
2019-01-03 08:44
@mboudreau Ok thanks .It would be good to have it

dagarwal
2019-01-03 08:45
One more question so to implement in this jenkins , i need to run the command to install it .any other way ? @mboudreau

mboudreau
2019-01-03 08:51
Well, when you use npm, it does install the Ruby binary, so you could hit it directly with the command. There's already a pull request for this change, I just need to spend some time to add it. Could you allow me a day to look the pr over and merge it and release a new version?

dagarwal
2019-01-03 08:52
wow that would be great , Sure .Please let me know when done :slightly_smiling_face:

jdesouza
2019-01-03 13:08
has joined #pact-js

matt.fellows
2019-01-03 22:20
Also if you haven't seen this, take a look


matt.fellows
2019-01-03 22:21
Examples of using the binaries from package.json

matt.fellows
2019-01-03 22:21
Once properly installed into the path it should he even easier

mboudreau
2019-01-04 06:09
@dagarwal I've updated pact-node to include `can-i-deploy`, version 6.21.0

matt.fellows
2019-01-04 06:58
:clap:

dagarwal
2019-01-04 10:18
wow thanks @mboudreau :slightly_smiling_face:

dagarwal
2019-01-04 10:28
Thanks Matt its good , i havent checked that link before

dagarwal
2019-01-04 10:44
@mboudreau Latest version for that is 6.20.2 as of now


dagarwal
2019-01-04 10:53
It gave me this ? Please choose a version of ?@pact-foundation/pact-node? from this list: (Use arrow keys) ? 6.20.2 6.20.1 6.20.0 6.19.12

mboudreau
2019-01-04 10:53
just update your package.json file to use 6.21.0 and do an `npm install`

dagarwal
2019-01-04 10:54
yeah it worked with that .I updated package and file and was doing yarn install and getting error

dagarwal
2019-01-04 10:54
Thanks

mboudreau
2019-01-04 11:04
must have been some caching or something

dagarwal
2019-01-04 11:04
yeah right

yousafn
2019-01-04 11:12
great work @mboudreau , I use pact-node and we were previously using the can-i-deploy standalone, so nice to have this option now :ok_hand:

mboudreau
2019-01-04 11:36
thanks :slightly_smiling_face:

mboudreau
2019-01-04 11:37
it was mostly @tjones doing the work, I just supervised :stuck_out_tongue:

dagarwal
2019-01-04 13:28
Thanks to @tjones too for the efforts :slightly_smiling_face:

dagarwal
2019-01-04 14:05
Hello @mboudreau @tjones thanks for can-i-deploy functionality .but it fails when we do can i deploy because in can-deploy.js file this.__argMapping , we are passing ?version?: ?--version?, but in the function we are using options.pacticipantVersion =options.pacticipantVersion instead of options.pacticipantVersion =options.version .I tried replacing the variables and it works fine .Please fix it . Do let me know if you want any further information .Thanks

mboudreau
2019-01-04 14:20
crap, sorry, you're right

dagarwal
2019-01-04 14:21
np .Please let me know once the update is ready :slightly_smiling_face:

mboudreau
2019-01-04 14:22
I'll do it now

dagarwal
2019-01-04 14:23
Perfect

mboudreau
2019-01-04 14:59
6.21.1 is building now, should be available in about 10 minutes

mboudreau
2019-01-05 08:22
Did this version work @dagarwal?

ilya.markevich1991
2019-01-05 21:07
has joined #pact-js

dagarwal
2019-01-06 15:36
no @mboudreau it is giving me same error

cdaly
2019-01-07 18:59
has joined #pact-js

dagarwal
2019-01-08 10:10
could you Please check @mboudreau

mboudreau
2019-01-08 10:11
whoops, didn't see this

mboudreau
2019-01-08 10:12
I'll get it done now

dagarwal
2019-01-08 10:12
Okay thanks

mboudreau
2019-01-08 10:52
wait, how are you calling can-i-deploy? can you give me an example of the command you use?

dagarwal
2019-01-08 10:54
yes I am doing like this

dagarwal
2019-01-08 10:54
const pactNode = require('@pact-foundation/pact-node'); const checkVerificationForProvider = { pacticipant: [Pacticpant1], version: ['1.0.0'], pactBroker: 'https://pact.ooflex.net/' }; pactNode.canDeploy(checkVerificationForProvider).then(() => { console.log("Verified can i deploy against Provider?); }).catch(err => { console.error("Verification failed for can i deploy Provider service", err); });

mboudreau
2019-01-08 10:55
can you change "version" for "pacticipantVersion" as see if it works?

dagarwal
2019-01-08 10:55
ok let me try

dagarwal
2019-01-08 10:57
The version must be specified using --version or --latest [TAG] for pacticipant flex-taxonomy-service Verification failed for can i deploy against flex taxonomy service Error: The version must be specified using --version or --latest

dagarwal
2019-01-08 10:57
i get this @mboudreau

mboudreau
2019-01-08 10:58
ah, yeah, I see it now

dagarwal
2019-01-08 10:58
i guess here we need to pass version only as in the internal code you are using it as pacticipactVersion

mboudreau
2019-01-08 10:59
the pact binary uses --version but I can't with the CLI in node since it messes up the CLI and thing --version is for the project version

mboudreau
2019-01-08 10:59
hence why I'm trying to use pacticipantVersion since it's also more descriptive

dagarwal
2019-01-08 10:59
okay so will you be changing the code accordingly ?

mboudreau
2019-01-08 10:59
yep, gimme a moment

dagarwal
2019-01-08 11:00
Sure ,thanks

mboudreau
2019-01-08 11:46
there's some tests missing here to make sure this doesn't break again. I'm going to release a quick fix for now, but I'll need to invest more time in the tests so that it won't ever break again :slightly_smiling_face:

dagarwal
2019-01-08 11:47
Sounds good :slightly_smiling_face:

mboudreau
2019-01-08 12:28
you going to be around in the next 10 minutes to make sure it works?

dagarwal
2019-01-08 12:29
Okay

mboudreau
2019-01-08 12:29
cool, sending it off for deployment, I'll let you know when it's up so you can confirm it works on your end and finish this for good :slightly_smiling_face:

dagarwal
2019-01-08 12:30
sure

mboudreau
2019-01-08 13:00
6.21.2 is out, please try it now :slightly_smiling_face:

mboudreau
2019-01-08 13:07
@dagarwal?

dagarwal
2019-01-08 13:07
yes trying

dagarwal
2019-01-08 13:09
it works :slightly_smiling_face: thanks @mboudreau

mboudreau
2019-01-08 13:10
woo!

mboudreau
2019-01-08 13:10
np, thanks for being patient :slightly_smiling_face:

rjmcguinness
2019-01-08 15:29
Hi Matt and all, Using Karma/Jasmine/Angular 7/Typescript with karma-pact, pact-node, pact-web. I have added the eachLike matcher to my tests but have run into a problem with my Jasmine text expectations. The Jasmine test is failing here https://gist.github.com/rorymcgit/7858c2e82f4d70341072d981dc70b54b#file-failing-eachlike-api-service-get-foo-pact-spec-ts-L62 because I have changed the body of the object to include the eachLike matcher. Previously in my `provider.addInteraction` I had: ``` willRespondWith: { status: 200, body: Matchers.somethingLike({ foo: [{ bar: ['a string'], }, { bar: ['another string'], }], }), } ``` Which meant I could `expect(response).toEqual(sameObjectAsWasPassedToBody)`. The only difference being wrapping it in a `somethingLike` above. Now I have: ``` willRespondWith: { status: 200, body: { foo: Matchers.eachLike({ bar: ['a string'], }), }, } ``` So I have to assert that the response is equal to a different object than what I have assigned to the `body` in the interaction. https://gist.github.com/rorymcgit/0bb82714b2de91fde8769b4acd668c2f#file-passing-eachlike-api-service-get-foo-pact-spec-ts-L68 My question is: What is the value of a Jasmine test in our Pact test, if all we are testing anyway is what has been passed into the `body`? We are not testing api method (as it is stubbed by the Pact provider service). The value of Pact from a consumer side is to generate the Pact and test our requests.

rjmcguinness
2019-01-08 16:03
I am tempted to remove the expectation and just `provider.verify()`

tjones
2019-01-09 03:54
The point of `expect` in a pact test like this is to be able to ensure that the correct domain object is returning to the caller of `getFoo()`. In Javascript, that is often (but not always) the same object that's on the wire

tjones
2019-01-09 03:54
if you're just returning the wire object without transformation, you could safely remove the expectation in your test

tjones
2019-01-09 03:56
However, what I like to do instead is to have a file of fixtures that describe the domain objects. This file is shared between the pact test's `expect` line, and the tests for the call site of `getFoo()`.

tjones
2019-01-09 03:58
This means that we can be sure that the callers of `getFoo()` and the pact between your foo client and provider are in sync

tjones
2019-01-09 03:58
With typescript, you probably don't need to do this

tjones
2019-01-09 04:05
without that `expect` call, you're missing out on: 1) Does the api method return the object? (guarding against misuse of the response in your `getFoo()`, eg returning `response` instead of `response.body`) With shared fixtures, or careful typescript types, you also get: 2) Does the api method return the same object that the caller expects?

matt.fellows
2019-01-09 04:07
:point_up: this

rjmcguinness
2019-01-10 09:48
Thanks for this, that?s very clear. I?ll keep the expectation and find a way to share the objects. Do you have any thoughts on programatically adding `eachLike`s? i.e. adding a test helper method that iterates over the object and replaces arrays with `eachLike(array[0])`.

tiago.ferrazmartins
2019-01-10 14:33
has joined #pact-js

tiago.ferrazmartins
2019-01-10 14:43
Have anyone done this before?


tjones
2019-01-14 06:13
I personally wouldn't do that, because the domain object (returned by the call site of your API) is a different object conceptually to the wire object (tested by pact verification), so I prefer them to be separate objects in code, even if they're very similar/the same. However, I don't think it's wrong to try it - If you prefer no duplication, then a helper like you suggest seems like the way to go. I'd be interested to know how you like it after a few months of use.

vicenzo
2019-01-28 22:03
has joined #pact-js

vicenzo
2019-01-28 22:05
Hello,

vicenzo
2019-01-28 22:05
can someone help me understand how the pact term works?

vicenzo
2019-01-28 22:05
i currently have a few done on my poc but when verifying i have no match done

vicenzo
2019-01-28 22:06
mocha is complaining about it

matt.fellows
2019-01-28 22:15
what have you tried so far?

matt.fellows
2019-01-28 22:15
It?s a regex matcher, which must correspond to the Ruby regex format. There are examples in the repo worth looking at first

matt.fellows
2019-01-28 22:16
Why would mocha care about the matcher? can you please elaborate?

vicenzo
2019-01-28 22:16
so I am validation iso8601DateTime

vicenzo
2019-01-28 22:17
the default regex available on the DSL works when using a web based validator

vicenzo
2019-01-28 22:17
but not when I do it on the pact

vicenzo
2019-01-28 22:18
the generate is being hard matched with the expected response

vicenzo
2019-01-28 22:18
I haven?t done the provider side yet I am starting at the consumer

vicenzo
2019-01-28 22:19
for example: ``` state: term({ matcher: 'ReviewPending|Approved|FundsPosted|SentToBank|Completed|RejectedFundsNotPosted|RejectedFundsNotSentToBank|RejectedUnapproved|RejectedValidationFailed|SendToBankFailed|FundsReturned|Postponed|Canceled', generate: 'Postponed', }),```

vicenzo
2019-01-28 22:19
the response from the provider will include any of those states

vicenzo
2019-01-28 22:20
``` transferTime: like('2018-12-18T21:21:28.619Z'), ```

vicenzo
2019-01-28 22:20
or different timestamps

matt.fellows
2019-01-28 22:27
What do you mean hard matched on the response? This doesn't make sense if your doing a consumer test.

matt.fellows
2019-01-28 22:27
Are you matching a response or a request?

matt.fellows
2019-01-28 22:28
Which one isn't working? The time or the other?

vicenzo
2019-01-28 22:34
``` interaction = { state: 'I have a list of transfer', uponReceiving: 'a request for all transfers', withRequest: { method: 'GET', query: 'page_size=5000', path: '/', }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: noFilter, } };``` `noFilter` has the Matchers ``` it('returns the correct response', async() => { await searchRequest().then((response) => { expect(response).to.eql(SEARCH_RESPONSE); }) });``` `SEARCH_RESPONSE` has a static JSON at the moment

matt.fellows
2019-01-28 23:06
What are you expecting to happen here? I expect `response` to have the values `2018-12-18T21:21:28.619Z` and `Postponed` in it

matt.fellows
2019-01-28 23:07
What?s the actual problem?

matt.fellows
2019-01-28 23:08
So this is a consumer test, any `generate` value provided to the `term` matcher will be what comes back from the mock service. Later on during provider verification, it will check what the provider actually responds with, and will use the `matcher` portion of the test to ensure it is what is expected

vicenzo
2019-01-28 23:17
Then why is that the SEARCH_RESPONSE (which is a copy json of the response of the provider) failing?

mboudreau
2019-01-28 23:19
@vicenzo are you sure that `.to.eql` is a deep equal? I thought it was a simple reference check just like `===` which won't work since the response is not the same object as the SEARCH_RESPONSE

mboudreau
2019-01-28 23:19
look to see if it has a `.to.deep.eql` instead

vicenzo
2019-01-28 23:19
the assertion error message is the same

vicenzo
2019-01-28 23:19
`AssertionError: expected { Object (pageCursorId, evaluatedTransfers) } to deeply equal { Object (pageCursorId, evaluatedTransfers) } <Click to see difference>`

mboudreau
2019-01-28 23:20
what's the difference?

tjones
2019-01-28 23:21
can you share the definitions of `noFilter` and `SEARCH_RESPONSE`?

vicenzo
2019-01-28 23:21
let me get a gist wipped up

tjones
2019-01-28 23:22
if it's chai, then I believe `eql` is the deep equal. `equals` is the reference check.

mboudreau
2019-01-28 23:23
wait, you're calling your API to return something that's auto generated?

tjones
2019-01-28 23:24
@vicenzo - are you hitting the pact mock server with this consumer test, or your real API?


vicenzo
2019-01-28 23:32
mock server @tjones

vicenzo
2019-01-28 23:32
```const provider = new Pact({ consumer: 'sentinel-ui', provider: 'sentinel-judge', host: 'localhost', port: MOCK_SERVER_PORT, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', logLevel: 'info', });```

vicenzo
2019-01-28 23:33
`searchRequest()` uses window to define the URL, I am just overriding the window global to point to the mock

vicenzo
2019-01-28 23:37
You are correct on that one

mboudreau
2019-01-28 23:51
why are you using term matchers for your response?

mboudreau
2019-01-28 23:52
I mean, it's fine, but then you have the SEARCH_RESPONSE which is static and then completely different from your interaction

mboudreau
2019-01-28 23:52
and you expect it to be the same

mboudreau
2019-01-28 23:53
which I don't really understand why you're doing this in the first place

vicenzo
2019-01-28 23:54
so maybe I am missing the point completely of how to write these tests

vicenzo
2019-01-28 23:54
I can flip the script

vicenzo
2019-01-28 23:54
would that fix it?

vicenzo
2019-01-28 23:55
oh right that was why

vicenzo
2019-01-28 23:55
when I use the matchers on the expect I get the pact json

vicenzo
2019-01-28 23:55
before it is run through the ruby cli

mboudreau
2019-01-28 23:58
well, I'm not sure why you're testing the response at all, it's kind of what pact does for you. All you want to do is make sure you test your API correctly and it's processing things correctly, and that the incoming body/query (not the response) has matchers so that the interactions are correct

mboudreau
2019-01-28 23:59
so, for instance, you have a `page_size` query with 5000, maybe you want to use a term for that so that it's always a number, and it can't be lower than X or higher than Y, then have tests to make sure that these limits are working with pact and your API

vicenzo
2019-01-29 00:00
I see

mboudreau
2019-01-29 00:00
or that another endpoint is a post and it expects a body of type Z with property blah of type something, but the response is always going to be the same thing

vicenzo
2019-01-29 00:00
this test is a bust basically because it doesn?t have the matcher on the request itself

vicenzo
2019-01-29 00:01
because it is the consumer

vicenzo
2019-01-29 00:01
if it was the provider than it would make sense to have the response matchers

mboudreau
2019-01-29 00:01
well, I wouldn't say it's a bust, you want a test to make sure that this interaction exists and it returns something, and that your consumer can parse the response and interact with it


vicenzo
2019-01-29 00:01
that was the point of this particular one

mboudreau
2019-01-29 00:02
but with the matchers and the like, not so much

mboudreau
2019-01-29 00:02
you don't need the matchers for the response

vicenzo
2019-01-29 00:02
``` willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: SEARCH_RESPONSE, } };```

vicenzo
2019-01-29 00:02
so here should be like that

vicenzo
2019-01-29 00:02
and the expect should be that the response.eql(SEARCH_RESPONSE)

vicenzo
2019-01-29 00:02
something like that?

mboudreau
2019-01-29 00:03
yes

mboudreau
2019-01-29 00:03
however, making sure that response equals response is a bit redundant

mboudreau
2019-01-29 00:03
maybe there's something in your consumer you want to test to make sure that this triggers and returns, then displays correctly?

mboudreau
2019-01-29 00:04
the point of your consumer test is to test the consumer, including the interaction with the API

mboudreau
2019-01-29 00:04
so, what's the function that calls this particular API endpoint? that's what you want to test

vicenzo
2019-01-29 00:04
`searchRequest()`

vicenzo
2019-01-29 00:04
this one

vicenzo
2019-01-29 00:05
```export function searchRequest(params) { const query = parseSearchQueryParams(params); return requests.get(`${URL(getAppConfigSetting('apiUrl'))}?${query}`); }```

mboudreau
2019-01-29 00:05
and it doesn't take any arguments or return anything?

mboudreau
2019-01-29 00:05
okay, that's better

mboudreau
2019-01-29 00:05
so, plenty of tests that can be done here based on the params

mboudreau
2019-01-29 00:05
see if the response fails, what does it do when it fails, what does it do when it succeeds, etc


vicenzo
2019-01-29 00:06
I see

mboudreau
2019-01-29 00:06
you can make it more complex as well if it's suppose to show something on the screen or update a state somewhere

vicenzo
2019-01-29 00:06
not this one

mboudreau
2019-01-29 00:06
ie. whatever in your consumer that calls `searchRequests`

vicenzo
2019-01-29 00:07
could I use pact to mock the api during a ui test?

mboudreau
2019-01-29 00:07
you sure can :slightly_smiling_face:

vicenzo
2019-01-29 00:07
:shocked_face_with_exploding_head:

mboudreau
2019-01-29 00:08
you can make it as minute as a test (unit tests, single function) or much wider and complex (e2e, ui)

mboudreau
2019-01-29 00:08
with state or multiple states

vicenzo
2019-01-29 00:11
right now I am just trying to get a POC done for consumer and provider

vicenzo
2019-01-29 00:11
maybe I should move to the provider and see if I can break the contract

vicenzo
2019-01-29 00:12
you?ll be seeing more of me soon =P

vicenzo
2019-01-29 00:12
thank you for the help and lesson!

mboudreau
2019-01-29 00:13
np :slightly_smiling_face:

vicenzo
2019-01-29 00:15
now back to the company network where I can;t send messages

dagarwal
2019-01-29 12:04
Hello guys , when i add pact matching with term here on path withRequest: { method: ?GET?, path: term({ matcher: ?/api/assets/[0-9]+?, generate: ?/api/assets/10006? }), }, ( I am getting 404 when i try to load the data on UI :disappointed: ) .Without adding matcher it just works fine for me . Any suggestions on what went wrong and how to achieve it ?

vitaliy.grigoruk
2019-01-30 20:05
has joined #pact-js

vitaliy.grigoruk
2019-01-30 20:08
Hey folks! Does pact-js has a full support for pact-specification v3 (https://github.com/pact-foundation/pact-specification/tree/version-3)? I'm wondering how can I specify providerStates as an array in my JS code instead of a single string.

matt.fellows
2019-01-30 20:18
@vitaliy.grigoruk no it doesn?t support all of v3, just the bits required to allow message pacts to work. So it?s v 2.x compatible you might say

vitaliy.grigoruk
2019-01-30 20:26
does anything speaks against adding support for providerStates then? I may contribute with a PR.

rafael.anachoreta
2019-02-01 13:46
has joined #pact-js

rafael.anachoreta
2019-02-01 13:57
hey! I'm trying to validate my Pact, but my consumer uses fetch and when I run it through node that fails :confused: (fetch is not defined, etc) any pointers on how I could solve it?

matt.fellows
2019-02-01 22:00
You could swap out the engine for something else (e.g. super agent) during test

matt.fellows
2019-02-01 22:01
Another option is to use the pact-web dependency which runs in browser test environments

matt.fellows
2019-02-01 22:01
There are examples in the repo of karma / Jasmine tests

abubics
2019-02-02 00:00
Or `isomorphic-fetch`?

matt.fellows
2019-02-02 00:01
Yep. I'd look to replace fetch as the simpler option. Pact is the easier library to deal with than pact web

rafael.anachoreta
2019-02-04 08:10
awesome, thanks for the responses. I was skeptical at first thinking this would mean replacing the actual behavior of my consumer, but looks like that isn?t the case

rafael.anachoreta
2019-02-04 15:01
another one: is there any matcher that would help with a return that can be a string or an object? ``` { target: "2019" } ``` or ``` { target: { value: 1000 } } ```

rafael.anachoreta
2019-02-04 15:02
my first idea was to use the term regex, but I figured that won?t work for objects

rafael.anachoreta
2019-02-04 15:02
p.s.: I realize that is probably not the best API design there can be, but it is what I must use :disappointed:

tomw
2019-02-04 17:23
has joined #pact-js

matt.fellows
2019-02-04 20:15
There is no single matcher that would do that. You would write (at least) two separate tests to ensure that it?s covered. You may use a provider state to document in which state the provider should be in too return either of the two formats (assuming it?s a similar looking requests that produces the two different shapes)

rafael.anachoreta
2019-02-05 08:16
thanks Matt, that helped :slightly_smiling_face:

karishnu
2019-02-05 11:06
has joined #pact-js

rafael.anachoreta
2019-02-05 14:33
okay hopefully my last question :slightly_smiling_face: I have my pact file ready but when I try to validate it against my provider, it fails. That happens because our infra has a proxy in place that changes the endpoints of the provider. Consumer: ``` GET local/api/zoo/animals ``` Provider: ``` GET local/zoo/animals ``` How can I handle this scenario? I?ve tried changing the host to use the /api (`localhost/api`) but that made my consumer tests fail :thinking_face:

rafael.anachoreta
2019-02-05 14:35
another thing to note is that the paths could be completely different depending on how it was set up (though that is less like)

matt.fellows
2019-02-05 19:44
Is it always consistently this new path? Or just in test or something?

rafael.anachoreta
2019-02-06 08:32
yes, it is consistent. We have explicit rules to route one thing to the other, but the consumer / provider don?t know about them :confused:

matt.fellows
2019-02-06 09:18
How/why do the consumer tests fail? Surely it's just a config item that sets the host and context path

rafael.anachoreta
2019-02-06 10:19
Sadly not a config file on either end. We have HAProxy set up doing the routing between the provider?s endpoint to something else entirely (in this case, adding /api/). The consumer (correctly) sends its requests to `/api/zoo/animals` and when the contract?s path is set to `/api/zoo/animals` the mock server is able to receive the request. With the same path, however, I?m unable to verify the provider is receiving the data from the mock server as requests are now being sent to `/api/zoo/animals` instead of `/zoo/animals` (as the provider expects). does that make sense?

matt.fellows
2019-02-06 13:14
Yes it does, I'm mostly confused as to how you can't modify the path the consumer uses during these tests. This is most bizarre. Can you explain why?

matt.fellows
2019-02-06 13:15
It's common. Some people will just test the apt with the proxy in front of it, some will remove it from the equation (there is commentary on our side Wendie about this).

rafael.anachoreta
2019-02-06 13:24
> Yes it does, I?m mostly confused as to how you can?t modify the path the consumer uses during these tests. This is most bizarre. Can you explain why? I?m not sure I follow. Do you mean implement a configuration system of sorts that changes the basepath in the implementation? Or by setting the path = ?/api/?? using Pact? this is the part (I think?) I shouldn?t change or it breaks the provider: ``` // in provider.addInteractions() withRequest: { method: "GET", path: "/zoo/animals", headers: { Accept: "*/*", }, }, ```

dagarwal
2019-02-06 15:17
how do we fail the build when can i deploy method is invoked and if verification was failed at provider side as we don?t return any exit code from the method ( can-deploy.js)?

dagarwal
2019-02-06 15:18
@mboudreau @matt.fellows

rafael.anachoreta
2019-02-06 16:18
I feel like I?m missing something important that would trivialize this, but I can?t figure out what :cold_sweat:

matt.fellows
2019-02-06 22:12
I haven't seen the API for can I deploy in JS yet so can't comment I'm afraid

matt.fellows
2019-02-06 22:16
Sure. So usually you have an http client that is configurable. When you setup your consumer application, you probably have to give it some information. Like where to find its provider (http url and path). Sometimes you can configure this with environment variables (e.g. `const providerBaseUrl = process.env.MY_PROVIDER_API = 'http://foo.com/path/to/api'`)

mboudreau
2019-02-06 22:25
@dagarwal is this for pact-node?

mboudreau
2019-02-06 22:25
because I'm fairly sure the pact-node version throws an error

matt.fellows
2019-02-06 22:46
Sounds about right to me. Can you programmatically detect which contract failed?

mboudreau
2019-02-06 22:47
hm, that I do not know. My gut says no, it just does the exit code but no extra data

mboudreau
2019-02-06 22:47
that sounds like a great feature to have though

mboudreau
2019-02-06 22:47
not sure how feasible it is with the current ruby binary however

matt.fellows
2019-02-06 23:01
I know that HA proxy is in the mix there - who manages that? The provider or another team? So this is the setup in prod: `[consumer] -> [HAProxy] -> [provider]` right? HAProxy is responsible for adding the `/api` bit of the path and performing the routing to the provider. If this is _not_ tested as part of provider verification (ie. you verify by pointing directly at the provider, bypassing HAProxy, which I?m guessing is the case) then you only have 3 options: 1. Put in a path that omits the `/api` is part of your consumer tests, but make sure the configuration in production puts this there. 2. Test the provider _via_ the HAProxy service 3. Wrap the provider in a teeny lightweight proxy when you test it, so that the paths don?t get out of alignment

dagarwal
2019-02-07 10:14
yes pact node .so when i use canDeploy we have console error as of now so even if i catch the error , build keeps on going and does not fail

rafael.anachoreta
2019-02-07 10:15
That makes sense, thanks a lot for sharing, Matt! :bow: I?ll discuss the options with the team and go from there. Do you think a feature request for it for Pact would fly? Another optional entry to the contract in `providerPath: string`?

matt.fellows
2019-02-07 10:18
It?s worth tabling. I can see it helping some, like yourself :slightly_smiling_face:

matt.fellows
2019-02-07 10:18
and no probs@

mboudreau
2019-02-07 10:50
if you catch the error without throwing another one, it'll gobble it up

mboudreau
2019-02-07 10:50
what are you using for your build system?

dagarwal
2019-02-07 10:50
jenkins

mboudreau
2019-02-07 10:51
okay, and how do you run it? what's the command?

dagarwal
2019-02-07 10:52
i am runnign like this return pactNode.canDeploy(checkVerification).then(() => { console.log(?Verified can i deploy against service?); }).catch(err => { console.log(?Verification failed for can i deploy against service?,err); });

dagarwal
2019-02-07 10:52
i am doing like this in code and runnign the js file on jenkins

dagarwal
2019-02-07 10:52
simply with node ?FileName?

mboudreau
2019-02-07 10:53
right, like I said, since you're catching the error, it never bubbles up to the node top level and thinks you handled it appropriately

dagarwal
2019-02-07 10:53
no even if i dont have catch in it, it does not fail my build

mboudreau
2019-02-07 10:54
there's a few different ways of doing it, one is to just throw the error again: ``` return pactNode.canDeploy(checkVerification).then(() => { console.log(?Verified can i deploy against service?); }).catch(err => { console.log(?Verification failed for can i deploy against service?,err); throw err; }); ```

mboudreau
2019-02-07 10:54
ah right, because it's a promise. You're probably not using something that handles promises in that way

dagarwal
2019-02-07 10:55
yes

dagarwal
2019-02-07 10:55
it just gives unhandled warning

dagarwal
2019-02-07 10:55
and the build goes on

mboudreau
2019-02-07 10:55
yeah

mboudreau
2019-02-07 10:56
one way of doing it is to just do `process.exit(1);` when the catch happens

mboudreau
2019-02-07 10:57
it'll make the program quit with an error code and jenkins will see that as a failed build

dagarwal
2019-02-07 10:57
so whats the way then ? i tried wrapping up the logic in test and did add expect condition to fail it .But i was being suggested its not a test .its part of build .

dagarwal
2019-02-07 10:58
okay i will try with process.exit and see

matt.fellows
2019-02-07 11:41
Also worth checking your Jenkins config. Make sure that any shell environment that you?re running in will also fail on non-zero exit codes

matt.fellows
2019-02-07 11:41
i.e. in in bash, make sure `set -e` is set

dagarwal
2019-02-07 11:47
okay will check

matt.fellows
2019-02-07 11:55
:thumbsup:

dagarwal
2019-02-07 16:00
it worked that way , thanks :slightly_smiling_face:

matt.fellows
2019-02-07 21:06
great!

matt.fellows
2019-02-07 21:06
Specifically, which way worked?

mboudreau
2019-02-07 22:45
the process.exit way :wink:

dagarwal
2019-02-08 09:08
yeah that way :stuck_out_tongue: but it would be good if canDeploy method return the same as its actually checking for if we can deploy or not so it should fail the build :slightly_smiling_face:

matt.fellows
2019-02-08 09:28
Process.exit is an antipattern for libraries - it makes sense for cli tools which check for error codes. Throwing errors or rejecting promises is much more idiomatic in JS. Errors are values and can be used as control flow. Process.exit is a blunt hammer

dagarwal
2019-02-08 09:29
oh i see ..makes sense

matt.fellows
2019-02-08 09:30
:ok_hand:


matt.fellows
2019-02-09 10:26
Thanks Rashi - i?m actually doing a few things now, will look at this :slightly_smiling_face:

arvindr3
2019-02-11 13:23
has joined #pact-js

arvindr3
2019-02-11 13:23
i m getting the issue while i m running the Pact Workshop - js Error: Error from response: undefined at request.get.query.then.err (D:\Pact\pact-workshop-js-master\consumer\client.js:33:15) at process._tickCallback (internal/process/next_tick.js:68:7)

matt.fellows
2019-02-11 20:24
At which step? What have you tried to fix it?

zach.the.hammer
2019-02-12 01:15
has joined #pact-js

arvindr3
2019-02-12 05:17
I m following the instructions given in the github page.I m first running the provider.js and in the seperate terminal i m running the Consumer.js file,while running consumer.js file i m getting the error that i have stated above.

robin
2019-02-15 13:59
has joined #pact-js

bernardo.guerreiro
2019-02-18 08:43
Hey @matt.fellows any update on this spike? I think this looked really good, do you have any plans to add it in a future release?

matt.fellows
2019-02-18 08:47
I plan on releasing in the next drop. Did you have any comment or feedback? Even a thumbs up on that issue would be great

vitaliy.grigoruk
2019-02-18 13:04
I?ll write down some feedback soon.

matt.fellows
2019-02-18 20:00
that?d be awesome

vinod.baradwaj
2019-02-19 17:06
I have an endpoint in my app which is like, `/api/actions?context=type;type=publish;assetIds=10006` with different matrix params `;` now when i create a consumer test with the same path, it throws `500` error. Can anyone here let me know how this can be fixed ? TIA

yousafn
2019-02-19 17:27
you may need to URLencode your path, I had the same issue sending `somepath/£$%` which becomes `somepath%2F%C2%A3%24%25` when encoded. In JS `const path = encodeURI("£$%");`

rickard.andersson
2019-02-20 07:04
has joined #pact-js

vinod.baradwaj
2019-02-20 13:14
this didn't solve my issue :disappointed:

matt.fellows
2019-02-21 07:45
Can you please share your test code so we can see? Logs would he nice too

vinod.baradwaj
2019-02-21 07:50
Hi Matt, this is my test code, ``` describe('Getting available action for publish', () => { before(() => { return provider.addInteraction({ given: 'GET call', uponReceiving: 'Get available action', withRequest: { method: 'GET', path: "/api/actions?context=type;type=publish;assetIds=10006" }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: actions } }); }); it('Get available actions for publish', () => { return request.get(`http://localhost:${PORT}/api/actions?context=type;type=publish;assetIds=10006`) .set({ 'Accept': 'application/json' }).then((response) => { return expect(Promise.resolve(response.status)).to.equal(200); }).catch(err => { console.log("Error in available actions", err); }); }); });``` and this is the logs which i get when i run the consumer tests,

vinod.baradwaj
2019-02-21 07:50
and this is the logs,


matt.fellows
2019-02-21 07:53
Thanks. I can take a look later when back at a desk

vinod.baradwaj
2019-02-21 07:53
thank you :slightly_smiling_face:

matt.fellows
2019-02-21 07:54
I'm actually not sure if or how we support matrix params.

matt.fellows
2019-02-21 07:55
What do the pact logs say?

matt.fellows
2019-02-21 07:55
From that, it just didn't match

vinod.baradwaj
2019-02-21 07:56
i see status `500` response in pact logs, ``` at process._tickCallback (internal/process/next_tick.js:180:9) status: 500, text: '{"message":"No interaction found for GET /api/actions?context=type;type=publish;assetIds=10006","interaction_diffs":[]}\n', method: 'GET', path: '/api/actions?context=type;type=publish;assetIds=10006' },```

vinod.baradwaj
2019-02-21 07:56
like you said it is not matching with the path with matrix params

matt.fellows
2019-02-21 07:57
That's the unit test logs, I'm talking about the one pact itself generates

vinod.baradwaj
2019-02-21 07:59
not sure... how can i get pact logs ?

matt.fellows
2019-02-21 08:01
There's an option in your pact test to specify where it goes. There is probably a log file in a `logs` or `pact` dir now

vinod.baradwaj
2019-02-21 08:06
got it, here goes the logs


vinod.baradwaj
2019-02-21 08:07
```I, [2019-02-21T13:33:57.330594 #6869] INFO -- : Received request GET /api/actions?context=type;type=publish;assetIds=10006 D, [2019-02-21T13:33:57.330712 #6869] DEBUG -- : { "path": "/api/actions", "query": "context=type;type=publish;assetIds=10006", "method": "get", "headers": { "Host": "localhost:30044", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Accept": "application/json", "Connection": "close", "Version": "HTTP/1.1" } } E, [2019-02-21T13:33:57.330820 #6869] ERROR -- : No matching interaction found for GET /api/actions?context=type;type=publish;assetIds=10006 E, [2019-02-21T13:33:57.330845 #6869] ERROR -- : Interaction diffs for that route: E, [2019-02-21T13:33:57.330869 #6869] ERROR -- :```

matt.fellows
2019-02-21 08:12
Based on that, you're library is sending thru the query string correctly (as a query string)

matt.fellows
2019-02-21 08:12
But your test is putting it the path only. Use the query option of the pact interaction

vinod.baradwaj
2019-02-21 08:14
let me try passing it as a param

matt.fellows
2019-02-21 10:10
How?d you go?

vitaliy.grigoruk
2019-02-21 13:18
@matt.fellows this is a tiny fix, will appreciate if we can get this merged/released

matt.fellows
2019-02-21 19:44
+:thumbsup: done


matt.fellows
2019-02-23 01:52
Would love your feedback gents, also on the examples/docs if they need further improvementn

matt.fellows
2019-02-23 02:02
:point_up: We?ve just removed one of the biggest complaints / pain points in Pact JS - the need for a `/setup` endpoint attached to your provider api. You can also now use `requestFilter`s to modify the req/res before sending to the provider. This is perfect for short lived bearer tokens: Example: ``` let token let opts = { provider: 'Animal Profile Service', ... stateHandlers: { "is authenticated": () => { token = "1234" Promise.resolve(`Valid bearer token generated`) }, "is not authenticated": () => { token = "" Promise.resolve(`Expired bearer token generated`) } }, // this middleware is executed for each request, allowing `token` to change between invocations // it is common to pair this with `stateHandlers` as per above, that can set/expire the token // for different test cases requestFilter: (req, res, next) => { req.headers["Authorization"] = `Bearer: ${token}` next() }, // This header will always be sent for each and every request, and can't be dynamic // (i.e. passing a variable instead of the bearer token) customProviderHeaders: ["Authorization: Bearer 1234"] } return new Verifier(opts).verifyProvider().then(...) ```

matt.fellows
2019-02-23 02:04
As you can see, to setup state all you need to do is register a handler in the verifier and it will be invoked by the framework before the test case is run. We use `requestFilter` to set an authorization header depending on the current state


m.r.green
2019-02-25 09:05
has joined #pact-js

vitaliy.grigoruk
2019-02-25 09:34
I?m sorry, I didn?t get back with results of my experiments last week. Due to specifics of our app, we need to wrap each pact verification (state setup + actual test request) into a single transaction (we run express server and launch pact from the same process). So, we need to start transaction before we actually set up state and rollback after a response is received from a server. So, I took your code from ^ spike and modified it to serve our needs. I?ve added `afterResponse` hook (to rollback a transaction) and `beforeSetup` hook to start a transaction. I?m passing transaction id via a header to app server inside `requestFilter`.

vitaliy.grigoruk
2019-02-25 09:35
I can contribute via a PR, in case this could be useful for others.

matt.fellows
2019-02-25 09:36
Ok thanks for feedback - not too late to add, but too late break :laughing:

matt.fellows
2019-02-25 09:38
I thought of having more hooks, but the request filter has the ability to do things to the response. The after hook could be useful for other purposes. If you have time, raising a feature enhancement on the repo is the best next step to get it in

vitaliy.grigoruk
2019-02-25 09:38
great, will do that!

matt.fellows
2019-02-25 10:02
:+1:

punarjit.singh
2019-03-01 03:10
has joined #pact-js

punarjit.singh
2019-03-01 03:10
Hi there... how are we supposed to pass request parameters in Pact Verifier ? are there any opts or do we need to use requestFilters... ?

matt.fellows
2019-03-01 03:11
what do you mean, sorry? Can you step back a bit and please let us know what you?re trying to do and where you?re at?

punarjit.singh
2019-03-01 03:32
Hi @matt.fellows so I am quite new to pact. I might be interpreting the docs in a wrong way. but here is what I'm trying to do: - I have followed the https://github.com/pact-foundation/pact-js#http-api-testing docs.... and created a mock provider within consumer spec. - the pacts are getting generated as expected. - next, I am trying to call the actual provider service (which is a real service hosted on my staging env). - Within my provider spec I am trying to verify the pacts.. - So I am calling Verifier().verifyProvider(opts) - to hit the actual api and verify the pacts... I am not sure how to pass the query parameters in the get request...

matt.fellows
2019-03-01 03:39
So the `verifyProvider` call should be configured to fetch pacts somehow (either from a local folder or from a pact broker). ALl of the details of the requests are in there, and pact will issue the requests against the provider for you

matt.fellows
2019-03-01 03:40
If there are query parameters that should be in the requests, you should have those defined in your consumer tests

punarjit.singh
2019-03-01 03:41
great... thanks a lot for pointing me in the right direction... will update my consumer tests

matt.fellows
2019-03-01 03:42
:thumbsup:

punarjit.singh
2019-03-01 04:35
Hey @matt.fellows .. m passing them as params: {abc: "xyz"} in consumer... pacts are getting generated but still without the params. I am using *axios* request

matt.fellows
2019-03-01 04:45
can you please share the test code ? Have you looked at the examples in the pact-js repo to see how they?re doing it?

punarjit.singh
2019-03-01 04:53
sorry I being so tempted to ask questions as its easy... yes m following the examples and tired a couple of things. trying a few more options... will share the test code if I couldn't resolve it soon

punarjit.singh
2019-03-01 04:54
well yes :smile: I got it working

matt.fellows
2019-03-01 04:57
hehe yes, asking is easier :slightly_smiling_face:

matt.fellows
2019-03-01 04:57
Doing is better! good job

punarjit.singh
2019-03-01 05:04
thanks.. here's the code snippets .. might help someone who's new to pact like me //index.js (provider mock) `'use strict';` `const axios = require('axios');` `exports.getPrices = endpoint => {` ` const url = endpoint.url;` ` const port = endpoint.port;` ` return axios.request({` ` method: 'GET',` ` baseURL: '${url}:${port}',` ` url: '/root/data?abc=XYZ',` ` headers: { "Content-Type": "application/json",}` ` });` `};` //Snippet from consumer.spec.js ` describe('get /root/data', () => {` ` before(done => {` ` const interaction = {` ` uponReceiving: 'a request for data',` ` withRequest: {` ` method: 'GET',` ` path: '/root/data',` ` headers: { "Content-Type": "application/json",},` ` query: {"abc": "XYZ"},` ` },` ` willRespondWith: {` ` status: 200,` ` headers: {` ` 'Content-Type': 'application/json'` ` },` ` body: EXPECTED_BODY` ` }` `};`

punarjit.singh
2019-03-04 01:43
Hey Guys... another quick question. My pact has two interactions, but when I run provider tests to verify this pact... only one interaction is verified. why is that ? Am I missing something Thanks!

matt.fellows
2019-03-04 01:45
hi!

punarjit.singh
2019-03-04 01:46
hey Matt

matt.fellows
2019-03-04 01:46
can you show us why it?s not working, or what leads you to think that?

matt.fellows
2019-03-04 01:46
also the pact contract that?s being verified

punarjit.singh
2019-03-04 01:48
sure. lemme remove any confidential info.. sharing in a while

matt.fellows
2019-03-04 01:49
:thumbsup:

punarjit.singh
2019-03-04 01:54
my pact looks like this... has 2 interactions (a request for data AND a request with missing or parameter)

punarjit.singh
2019-03-04 01:59
Provider (actual service) Pact Test

punarjit.singh
2019-03-04 02:01
please check if this info helps...

punarjit.singh
2019-03-04 02:04
also m not setting the PACT_DESCRIPTION env variable to run any individual interactions

matt.fellows
2019-03-04 02:04
ok, so the provider test is just a single ?test? but how do you know it?s not making multiple calls to your provider?

matt.fellows
2019-03-04 02:04
Try modifying the pact.json file (by hand if you need) so that it hits a different path, and see if it fails

punarjit.singh
2019-03-04 02:06
I thought the single test would run all the interactions... newbie mistakes maybe... by hitting diff path you mean I should change the endpoint uri ?

matt.fellows
2019-03-04 02:09
The single test does run all the interactions - how do you know it?s not?

matt.fellows
2019-03-04 02:10
so i mean modify `"path": "/root/data",` to something else like `"path": "/path/doesnt/exist/so/i/should/see/a/failure,`

matt.fellows
2019-03-04 02:10
then you can see if it?s performed both tests

punarjit.singh
2019-03-04 02:10
coz in the run log.. it only shows one interaction passed

punarjit.singh
2019-03-04 02:10
sure

matt.fellows
2019-03-04 02:10
oh I see

matt.fellows
2019-03-04 02:10
sorry it was hard to see that

punarjit.singh
2019-03-04 02:11
sorry about that.

matt.fellows
2019-03-04 02:11
np

matt.fellows
2019-03-04 02:11
Are you sure it?s reading the correct pact file?

punarjit.singh
2019-03-04 02:11
yes

punarjit.singh
2019-03-04 02:11
there's only one

matt.fellows
2019-03-04 02:11
the one you shared with me has 2

punarjit.singh
2019-03-04 02:11
no wait.. you're right

matt.fellows
2019-03-04 02:12
:smile:

punarjit.singh
2019-03-04 02:12
pact file is wrong

punarjit.singh
2019-03-04 02:12
my bad

matt.fellows
2019-03-04 02:12
haha

punarjit.singh
2019-03-04 02:13
silly me.. sorry for your time mate. thank you so much

matt.fellows
2019-03-04 02:13
np

josh.mccure
2019-03-05 01:07
has joined #pact-js

jeffm
2019-03-05 19:24
I'm having a bit of trouble understanding how matchers work with request paths. Is there a good example to look at?

jeffm
2019-03-05 19:26
The API I'm testing has a path segment which is a timestamp

matt.fellows
2019-03-05 19:26
what have you tried?

jeffm
2019-03-05 19:28
I presume I have to setup matchingRules with $.path in the request?

matt.fellows
2019-03-05 19:31
yep

matt.fellows
2019-03-05 19:31
look at the e2e example in the repository, there is a matcher example for paths in there

matt.fellows
2019-03-05 19:33
``` provider.addInteraction({ state: "Has an animal with ID 1", uponReceiving: "a request for an animal with ID 1", withRequest: { method: "GET", path: term({ generate: "/animals/1", matcher: "/animals/[0-9]+" }), headers: { Authorization: "Bearer token" }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: animalBodyExpectation, }, }) ```

matt.fellows
2019-03-05 20:37
How'd you go?

jeffm
2019-03-05 21:05
~Thanks, will try again this afternoon~

jeffm
2019-03-05 21:06
Thanks, we'll give it a try this afternoon.


matt.fellows
2019-03-05 21:08
Yep

jeffm
2019-03-05 23:35
Using `term` worked. Thank you. We're now matching the expected request, although struggling through debugging why the body of the provider response does not match: `Expected a Hash but got a String`

jeffm
2019-03-05 23:39
``` body: { 't': { 't': Matchers.term({ generate: `${subscribeTime}`, matcher: '[0-9]+' }), 'r': 2 }, 'm': [] }, -{ - "t": { - "t": "15518280219750000", - "r": 2 - }, - "m": [, - - ] -} +"{\"t\":{\"t\":\"15518279409297495\",\"r\":2},\"m\":[]}" ```

matt.fellows
2019-03-06 00:12
I think you need to match on the content type

matt.fellows
2019-03-06 00:12
As json

matt.fellows
2019-03-06 00:13
Either that, or your app is not sending JSON and is sending a string

rjmcguinness
2019-03-06 09:49
Hi pact-js team, Do you have any recommendations for dealing with matching nested arrays? For example, I have a payload object with a property `option` which is an array of objects containing arrays, see below. ``` const dummyPayload = { options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], }, {name: 'option name 2, data...} ], }; ``` The below works, but is quite hard to read. This is a simplified example, and some of our responses have deeper nesting. ``` const dummyResponsePact = { options: Matchers.eachLike({ ...dummyPayload.options, data: Matchers.eachLike(dummyPayload.options[0].data[0]), }), }; ```

matt.fellows
2019-03-06 09:50
Can you just not wrap the whole thing in a single `like` matcher?

rjmcguinness
2019-03-06 09:59
Looks like `like` is just an alias for `somethingLike`, which I am actually currently wrapping this object with when adding interactions (sorry that was not visible in the example). The `somethingLike`/`like` matcher doesn?t deal with arrays like `eachLike` does though. My intent is to have all the arrays in my object, however deeply nested, match at the one or more level, outputting the below in the pact: ``` "matchingRules": { "$.body": { "match": "type" }, "$.body.options": { "min": 1 }, "$.body.options[*].*": { "match": "type" }, "$.body.options[*].data": { "min": 1 }, "$.body.options[*].data[*].*": { "match": "type" } } ```

matt.fellows
2019-03-06 11:15
My understanding is that wrapping the entire block in just a `like` - with no nested matchers - should automatically and recursively set type matchers (incl. to arrays) as it goes down the tree. Is this not happening?

rjmcguinness
2019-03-06 11:21
This is the only type matcher I get in the Pact json when passing the raw object into `Matchers.like()` ``` "matchingRules": { "$.body": { "match": "type" } } ```

asad
2019-03-06 12:28
has joined #pact-js

asad
2019-03-06 12:34
Hi i have a provider test as follow (using jest and using message queue) ``` /* eslint-disable no-undef */ const { MessageProviderPact } = require('@pact-foundation/pact'); const path = require('path'); const { getMsg } = require('./../mock-prestac'); describe('Message provider tests', () => { const p = new MessageProviderPact({ messageProviders: { 'a request for prepare': () => getMsg(), }, log: path.resolve(process.cwd(), 'logs'), provider: 'prestac', providerVersion: '1.0.0', logLevel: 'fatal', pactUrls: [ path.resolve(process.cwd(), 'pacts', 'prepare-prestac.json'), ], }); describe('send a prepare message', () => { it('sends a valid prepare message', () => { p.verify(); }, 30000); }); }); ``` its working test pass but it dont exit and produce some error as follow ``` PASS tests/provider.test.pact.js (5.797s) Message provider tests send a prepare message ? sends a valid prepare message (18ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 7.742s Ran all test suites. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. (node:11280) UnhandledPromiseRejectionWarning: Error: INFO: Reading pact at /xampp/htdocs/prepare-service/pacts/prepare-prestac.json Verifying a pact between prepare and prestac Given message is valid a request for prepare has matching content (FAILED - 1) Failures: 1) Verifying a pact between prepare and prestac Given message is valid a request for prepare has matching content Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'message is valid' for consumer 'prepare' at http://localhost:63714/_pactSetup. response status=415 response body=<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at C:\xampp\htdocs\prepare-service\node_modules\body-parser\lib\read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (C:\xampp\htdocs\prepare-service\node_modules\raw-body\index.js:224:16)<br> &nbsp; &nbsp;at process.internalTickCallback (internal/process/next_tick.js:70:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * A request for prepare given message is valid (node:11280) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:11280) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ```

matt.fellows
2019-03-06 19:44
I think that's correct. Is it not doing what you would expect? Forget the serialisation into pact for a second, does the consumer and provider test work as expected?

matt.fellows
2019-03-06 21:34
you need to return the `p.verify()` as it?s a promise. That?s why you?re getting a green test but an error printed out after

matt.fellows
2019-03-06 21:35
You should also setup a state handler for the ?message is valid? state

asad
2019-03-07 09:03
Thank for help will try your suggestion :+1:

asad
2019-03-07 09:58
hey can you provide me example of state handler? m not able to find it in https://github.com/pact-foundation/pact-js/tree/master/examples/messages

asad
2019-03-07 10:17
found it in https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/provider.spec.js i am now returning `p.verify()` but still getting same error (no green test this time, guess it was not green before either just was not throwing error before showing test as green) This is the output i am getting ``` $ npm run test:provider > render-service@1.0.0 test:provider C:\xampp\htdocs\render-service > jest --testRegex "/*(provider.test.pact.js)" --runInBand --setupFiles ./tests/config/pactSetup.js --setupTestFrameworkScriptFile=./tests/config/pactTestWrapper.js [2019-03-07T10:14:23.616Z] INFO: pact-node@6.21.5/3360 on DESKTOP-KOB10PR: Creating Pact Server with options: consumer = render, cors = false, dir = C:\xampp\htdocs\render-service\pacts, host = 127.0.0.1, log = C:\xampp\htdocs\render-service\pact logs\pact-tests.log, pactFileWriteMode = update, port = 8991, provider = prestac, spec = 2, ssl = false, sslcert = , sslkey = FAIL tests/provider.test.pact.js (6.689s) Message provider tests send a render message × sends a valid render message (2046ms) ? Message provider tests ? send a render message ? sends a valid render message INFO: Reading pact at /xampp/htdocs/render-service/pacts/render-prestac.json Verifying a pact between render and prestac Given message is valid a request for rendering has matching content (FAILED - 1) Failures: 1) Verifying a pact between render and prestac Given message is valid a request for rendering has matching content Failure/Error: raise "An error was raised while verifying the message.The response body is: #{response.body}" RuntimeError: An error was raised while verifying the message. The response body is: {} 1 interaction, 1 failure Failed interactions: * A request for rendering given message is valid at ChildProcess.<anonymous> (node_modules/@pact-foundation/pact-node/src/verifier.ts:172:57) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 10.63s Ran all test suites. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ```

krzysztof.stepniak
2019-03-07 10:34
has joined #pact-js

krzysztof.stepniak
2019-03-07 10:38
Hi guys, I have problem with matchers when I?m using them on headers and body for post wiht header `mulipart/form-data`. When I use regex which should enable all characters `[\\s\\S]*` post always end with 500 on mock server. I can send you part of code if its more descriptive.

matt.fellows
2019-03-07 10:41
My apologies, you don?t need a state setup for this. Att least, it?s not mandatory.

matt.fellows
2019-03-07 10:41
What?s the pact logs say? It appears as if the content isn?t matching, which means its a legitimate failure

matt.fellows
2019-03-07 10:49
The state is also passed in to the registered handler, so that can setup any state required if needed too

krzysztof.stepniak
2019-03-07 10:52
Funny thing is that the commented matchers are not matched by pact correctly inspite of that they goes through ruby and js regex. Pactjs shows two the same with error that is not the same /shrug

matt.fellows
2019-03-07 10:54
What does the pact logs have to say about it?

krzysztof.stepniak
2019-03-07 10:55
oh wait

krzysztof.stepniak
2019-03-07 10:55
not that

matt.fellows
2019-03-07 10:55
as an aside, this is a bit wrong: ``` after(async () => { return await platformBFF.finalize(); }); ``` remove the async and await

matt.fellows
2019-03-07 10:55
you can simply return the promise here - no need to await for it and then return. That?s just a double wrapped promise :slightly_smiling_face:

krzysztof.stepniak
2019-03-07 10:56
mkay

matt.fellows
2019-03-07 10:57
(there?s a few examples of that)

matt.fellows
2019-03-07 10:58
also, what?s this all about? It looks like you?re trying to ensure a project is created before running the consumer tests? is that right? ``` projectId = (await setup.createProject('floor', token)).body._id; ```

krzysztof.stepniak
2019-03-07 10:58
yes it is for provider side

krzysztof.stepniak
2019-03-07 10:59
i want to extract id and create project on real service and pass his id

krzysztof.stepniak
2019-03-07 10:59
it works fine in other tests

matt.fellows
2019-03-07 11:03
you can?t do that in pact

krzysztof.stepniak
2019-03-07 11:03
Test is all about creating via POST new floor which have picture and name. To get there you need to create previously project and there you are creating floor

matt.fellows
2019-03-07 11:04
I understand, but that is a scenario / functional tests.

matt.fellows
2019-03-07 11:04
I?d suggest taking a read through the FAQ


krzysztof.stepniak
2019-03-07 11:05
this path is used by mobile team

krzysztof.stepniak
2019-03-07 11:05
i only want to check this one endpoint

matt.fellows
2019-03-07 11:05
Aside from that, it just won?t work. Your consumer tests, if using Pact, hit the Pact mock server. . So creating a project and then hitting the pact endpoint has no impact on that test

matt.fellows
2019-03-07 11:06
I?ve added a state handler example to message pact just now too

krzysztof.stepniak
2019-03-07 11:07
Im not sure if i understand it correctly.

matt.fellows
2019-03-07 11:07
Have you read those FAQs?

krzysztof.stepniak
2019-03-07 11:07
Im just mocking floor endpoint thats all

krzysztof.stepniak
2019-03-07 11:07
yep

krzysztof.stepniak
2019-03-07 11:15
So im digging too deep in this test?

asad
2019-03-07 11:16
Attached the logs. it include warn and error ``` W, [2019-03-07T12:19:48.394818 #17152] WARN -- : Could not load existing consumer contract from C:/xampp/htdocs/render-service/pacts/render-prestac.json due to undefined method `gsub' for nil:NilClass. Creating a new file. E, [2019-03-07T12:19:48.394818 #17152] ERROR -- : undefined method `gsub' for nil:NilClass (NoMethodError) ```

matt.fellows
2019-03-07 11:18
sorry, was afk

matt.fellows
2019-03-07 11:19
so take me through what yoou?re doing

matt.fellows
2019-03-07 11:19
1. the `createProject` 2. the `postFloor` bit

matt.fellows
2019-03-07 11:20
Something is wrong with the contract - how did it get created? Did you create it by hand?

asad
2019-03-07 11:21
no i have consumer test which creates it, i delete it and create from consumer again

matt.fellows
2019-03-07 11:21
ok

matt.fellows
2019-03-07 11:22
could you please share the contract with us? Or a minimal version of it that creates that error? It seems that it is not being serialised correctly. That?s a bug somewhere

krzysztof.stepniak
2019-03-07 11:30
ok

krzysztof.stepniak
2019-03-07 11:31
createProject is just for provider side to reach floor with exact id which im passing into consumer contract

asad
2019-03-07 11:31
my consumer test code ``` const { MessageConsumerPact, asynchronousBodyHandler, } = require('@pact-foundation/pact'); const path = require('path'); const { validateMessage } = require('./../render'); const msg = { identifier: {}, body: { projectId: 538481, projectPath: 'C:/xampp/htdocs/render-service/538481.aep', movPath: 'C:/xampp/htdocs/render-service/538481.mov', mp4Path: 'C:/xampp/htdocs/render-service/538481.mp4', }, }; describe('Message consumer tests', () => { const messagePact = new MessageConsumerPact({ consumer: 'render', dir: path.resolve(process.cwd(), 'pacts'), pactfileWriteMode: 'update', provider: 'prestac', logLevel: 'fatal', }); describe('Receive a valid message for rendering', () => { it('Process rendering', () => messagePact .given('message is valid') .expectsToReceive('a request for rendering') .withContent(msg) .verify(asynchronousBodyHandler(validateMessage)), 600000); }); }); ``` and the contract it generate is ``` { "consumer": { "name": "render" }, "provider": { "name": "prestac" }, "messages": [ { "description": "a request for rendering", "providerStates": [ { "name": "message is valid", "params": null } ], "contents": { "identifier": { }, "body": { "projectId": 1, "projectPath": "path", "movPath": "path", "mp4Path": "path" } }, "matchingRules": { "body": { } }, "metaData": { } } ], "metadata": { "pactSpecification": { "version": "3.0.0" } } } ```

krzysztof.stepniak
2019-03-07 11:31
Project ---> Floor . You cant create floor without project

matt.fellows
2019-03-07 11:32
does that actually create a project in the provider side?

matt.fellows
2019-03-07 11:32
or mock it out, as you said before?

krzysztof.stepniak
2019-03-07 11:32
It creates real project on service.

krzysztof.stepniak
2019-03-07 11:32
not mocked

krzysztof.stepniak
2019-03-07 11:33
Consumer gets just id which is passed into path

matt.fellows
2019-03-07 11:33
> You cant create floor without project This is what we are referring to as a functional test, specifically for the provider. This sort of test belongs in the provider, not the consumer.

matt.fellows
2019-03-07 11:33
Further more, with Pact, if your next test is to create the floor you?re not going to hit the provider service - you?re going to hit the Pact mock server. It doesn?t need the project to be created - it has no idea

krzysztof.stepniak
2019-03-07 11:34
so in that case when i use verify from provider side it didn?t get through

krzysztof.stepniak
2019-03-07 11:35
because real service did not get id and so on

matt.fellows
2019-03-07 11:35
No, nothing you do in the consumer tests touches the real provider. That?s by design - otherwise you don?t need Pact, you can just do the usual e2e testing. Pact means that you can test each system separately as _unit tests_

matt.fellows
2019-03-07 11:35
correct

krzysztof.stepniak
2019-03-07 11:36
mkay

matt.fellows
2019-03-07 11:36
each interaction should be tested on its own, and as close to a unit test as possible. The more setup you find yourself doing for a test is a smell that something is not right, and the test is getting too broad

krzysztof.stepniak
2019-03-07 11:36
ok

krzysztof.stepniak
2019-03-07 11:38
ok, so lets back to interaction provided by me

krzysztof.stepniak
2019-03-07 11:38
why this return 500 from mocked server

krzysztof.stepniak
2019-03-07 11:39
I know you are talking that my test is not correct because I am setting up things from provider side in consumer test but it has nothing to do with 500 from mock server

matt.fellows
2019-03-07 11:40
Something to do witht ASCII-8BIT

krzysztof.stepniak
2019-03-07 11:41
yeah encoding stack

krzysztof.stepniak
2019-03-07 11:42
I saw that it is common stack in pact

matt.fellows
2019-03-07 11:42
mmm yeah I?ve seen this before, but I?m not sure it?s ever been resolved


matt.fellows
2019-03-07 11:42
Might be worth looking at the ruby standalone ruby and giving it a bump

krzysztof.stepniak
2019-03-07 11:44
mkay, thanks for your help Randy :wink:

matt.fellows
2019-03-07 11:44
hahaha

matt.fellows
2019-03-07 11:44
no probs, and sorry. I?ll have a look again tomorrow, but it?s late here and I should get to bed

matt.fellows
2019-03-07 11:44
good luck!

krzysztof.stepniak
2019-03-07 11:44
cya

rjmcguinness
2019-03-07 11:50
I didn?t think so, but I am not part of the provider team so will have to dig into this to see. Thanks, I?ll let you know what I find

phil.a.herbert
2019-03-07 15:57
has joined #pact-js

phil.a.herbert
2019-03-07 16:06
Hello! Does anyone know if there has been any work done towards matching on dynamic object keys? (see https://github.com/pact-foundation/pact-specification/issues/47, https://github.com/DiUS/pact-jvm/issues/313). It?s seemingly in the v4 spec (https://github.com/pact-foundation/pact-specification/tree/version-4#ignoring-the-keys-in-a-map), but given that it?s been implemented in pact-jvm, I?m curious to know if anyone has thought about it for pact-js. I would also be happy to have a go at implementing it if: a) it?s not too complicated for someone new to the repo b) people think it?s a good idea

matt.fellows
2019-03-07 23:22
It?s definetely a good idea, but you would need to get it into the Ruby implementation (as that?s used under the hood in all but the JVM based ones)

matt.fellows
2019-03-07 23:22
You want to raise an issue at https://github.com/pact-foundation/pact-ruby/

matt.fellows
2019-03-07 23:22
(if there?s not already one)

asad
2019-03-08 07:24
hey @matt.fellows did you looked into message i sent? is there something wrong with my code or bug in pactjs?

matt.fellows
2019-03-08 07:44
Which message, sorry

asad
2019-03-08 08:21
in the previous thread :stuck_out_tongue: guess i will add it here agian


matt.fellows
2019-03-08 11:04
Sorry I must have missed it. But it's not showing up well on my phone (I'm out tonight). I'll try to look tomrrow sorry


asad
2019-03-11 07:23
any updates on this @matt.fellows :slightly_smiling_face:

matt.fellows
2019-03-11 07:43
Hmm no sorry, could you please raise a ticket on pact-js repo?

matt.fellows
2019-03-11 07:43
You shouldn?t be able to create a problem with the contract file using nothing but our tools

matt.fellows
2019-03-11 07:43
sorry!

asad
2019-03-11 07:48
ok i will and np

matt.fellows
2019-03-11 07:51
thanks mate!

asad
2019-03-11 07:59
created the issue let me know if you would need more info :slightly_smiling_face:

matt.fellows
2019-03-11 08:54
:+1:

matt.fellows
2019-03-11 23:09
@yousafn let me know how the above goes, hopefully has sorted the issue!

yousafn
2019-03-11 23:25
hey mate will try it now :slightly_smiling_face:

yousafn
2019-03-11 23:45
good spot on the v2 in the url. pact-js now passing which means the pact-node job is failing for same reason, click on the pact-node job to see. https://circleci.com/workflow-run/28225c87-ffb3-4ad2-bed6-37e627b9a2a2 I can raise an issue against pact-node if you want? also got an aside issue, I can?t call a https pact broker that doesn?t have a CA, (default nginx config from the example docs) that job is also shown in that workflow thanks again dude

matt.fellows
2019-03-12 02:31
no probs. I?m having accessing that link (getting a 404) - is it a public build?

matt.fellows
2019-03-12 02:32
nvm, just needed to login

matt.fellows
2019-03-12 02:33
The pact node job i think is failing because it?s hitting the same problem i.e. `/v2/v2/...`

matt.fellows
2019-03-12 02:33
Note the error is a `404` not an SSL issue

matt.fellows
2019-03-12 02:33
oh, hmmm

matt.fellows
2019-03-12 02:35
Not sure why it?s 404ing, but you might want to bump the log level and see if anything useful turns up

yousafn
2019-03-12 10:46
Morning chap (probably late night for you) - Will have a look into it today whilst I?m at work. Not entirely clear on how to bump the log level as there doesn?t appear to be a logging param on the verifyPacts

matt.fellows
2019-03-12 10:57
`logLevel: "DEBUG"` should do it

matt.fellows
2019-03-12 10:57
oh, right. Pact-node probably doesn?t have that, no

matt.fellows
2019-03-12 10:57
just pact-js

yousafn
2019-03-12 12:15
It will only work if `pact.logLevel('DEBUG');` outside of the pact.verifyPacts(opts) block but that only outputs the debug output for the pact-binary. Not really an issue for me now that we have the ability to switch off sslverification in pact-js. I will propose a PR in the next couple of days just to add that new option to the readme

adamgreen
2019-03-12 15:37
Hi all, having some trouble getting a pact test to run using the ApolloGraphQLInteraction in Angular using Karma etc. When I run ng test I get the following error (see thread), any ideas what i'm probably doing wrong? Thanks in advance

matt.fellows
2019-03-12 22:20
Hmm `ApolloGraphQLInteraction` is not a type in the `pact-web` package. Could you please raise an issue for this? It probably should be.

matt.fellows
2019-03-12 22:20
You _should_ be able to get it from the `@pact-foundation/pact` package, though in the mean time

adamgreen
2019-03-13 07:55
Hi Matt, thanks for getting back to me, i'll raise that right now. I did try taking it from /pact as i'd noticed in the example for graphql, but i get a different error ERROR in src/app/pact/pact-component.pact.spec.ts(62,33): error TS2345: Argument of type 'ApolloGraphQLInteraction' is not assignable to parameter of type 'InteractionObject | Interaction'. Type 'ApolloGraphQLInteraction' is not assignable to type 'Interaction'. Property 'state' is protected but type 'Interaction' is not a class derived from 'Interaction'. Thanks again

matt.fellows
2019-03-13 08:13
Ok cool, looks like we need to port that across. Should be straightforward

matt.fellows
2019-03-13 08:21
Your could probably do some nasty casting there in the meanwhile

asad
2019-03-15 12:33
Hi i am trying to run https://github.com/pact-foundation/pact-js/tree/master/examples/messages locally on my system (windows 10) as it is, i pulled repo pact-js moved to example messages did `npm i` after that m trying to run consumer and provider test but both are giving same error ` Error: The system cannot find the path specified.`

asad
2019-03-15 12:33
provider test output

matt.fellows
2019-03-15 20:49
Have you run npm I the root folder and project folder?

sergiy
2019-03-17 14:34
has joined #pact-js

asad
2019-03-18 06:55
yes i run npm I in root folder as-well

evan_l00
2019-03-20 00:49
has joined #pact-js

evan_l00
2019-03-20 00:52
Hi, based on my understand, there are many libraries could do the contract testing and why pact stands out? I think I can use newman(postman's command line) to automate the requests and verify the response like the pact does.

matt.fellows
2019-03-20 00:53
sure, but that?s not contract testing

matt.fellows
2019-03-20 00:53
that?s just API/HTTP testing

evan_l00
2019-03-20 00:53
What's the difference between contract testing and API testing. I read this link By read this link https://docs.pact.io/best_practices/consumer/contract_tests_not_functional_tests

evan_l00
2019-03-20 00:54
I think the contract testing mention in the link just a loose API testing. contract just test fewer cases

matt.fellows
2019-03-20 00:54
Contract tests checks both sides of the API contract - the consumer and the provider. It ensures that _both_ sides of the contract are in sync, preventing drift

matt.fellows
2019-03-20 00:55
It?s easy to have a swagger defined for a provider API, and even check that the provider is compatible with it (if that?s what yyou do). It?s harder to be sure, that the consumer implements the contract correctly

matt.fellows
2019-03-20 00:56
Contract testing let?s you test each side of this _independently_ - meaning you don?t need to have both services running to ensure they are compatible. This enables much simpler continuous delivery

matt.fellows
2019-03-20 00:57
Without contract testing, you can?t be sure, and therefore have to start up all the services together and test them at the same time to make sure they?re compatible. This is slow, problematic, fragile and cumbersome

evan_l00
2019-03-20 00:58
Firstly thank you for your kind help and detailed answer!! :slightly_smiling_face: My further question is for the corps that one team owns the consumer and the other team owns the provider.

evan_l00
2019-03-20 00:59
The provider team cannot wait the consumer team to provide the pact.

matt.fellows
2019-03-20 00:59
you?re welcome

evan_l00
2019-03-20 01:00
because in most of the case, the provider will be developed first. And in the provider developing time, the provider team needs to test their service.

matt.fellows
2019-03-20 01:00
Sure, and they should absolutely test their service through whatever means makes sense. The contract can be generated later by the consumer when they?re ready, at which point the provider can verify it.

matt.fellows
2019-03-20 01:01
All of the functional testing of the provider still needs to be done, it just should be done by the provider team (not the consumer team, via e2e tests).

matt.fellows
2019-03-20 01:01
for that, whatever tool gets the job done is fine

matt.fellows
2019-03-20 01:01
so newman can definitely be used with Pact

matt.fellows
2019-03-20 01:01
newman = functional test, pact = contract test

matt.fellows
2019-03-20 01:02
functional test = the API does what it says it does contract test = the parties that use the API are always in sync with how the API should be used

matt.fellows
2019-03-20 01:03
bbl sorry, in meeting

evan_l00
2019-03-20 01:05
Please be proud that you can answer questions from new comers like me :slightly_smiling_face:.

evan_l00
2019-03-20 01:07
These days I have tried with do a API-test with my new provider with the pact-js. Your answers clear most of the doubts I met during the process. Thank you very much!

evan_l00
2019-03-20 01:13
So contract testing is an extra insurance for the software. If the consumer and provider teams develop separately, provider team will still need the verify the provider by API-testing. And the consumer team will provide the contract pact while writing the consumer and later give the pact to the provider to verify the provider. In the future, the provider could use the pact to verify its new change and the consumer could verify itself by the pact. Is my understanding correct? Last but not least, deeply thank you for you answer!

bethskurrie
2019-03-20 01:14
Yes, this is correct.

evan_l00
2019-03-20 01:14
Thank you, Beth!

abubics
2019-03-20 03:19
@evan_l00 Another thing you can do (from the provider side, while waiting for consumers to exist) is write your own test consumer. It doesn't have the full value of a real consumer, but it can exercise your CI/CD testing infrastructure :slightly_smiling_face:

evan_l00
2019-03-20 23:21
Create a thread

evan_l00
2019-03-20 23:22
@abubics CI/CD testing infrastructure could be also exercise by other test frameworks. I don't any pros here

matt.fellows
2019-03-20 23:23
I think by ?infrastructure? in this context, Boris means ?your CI/CD scripting process?. Not testing actual server/cloud infrastructure.

matt.fellows
2019-03-20 23:23
i.e. it prepares you for when the ecosystem grows to multiple consumers and providers

evan_l00
2019-03-20 23:25
It seems this a over-thinking idea. Too many purposes on one framework seems bring too much complexity

evan_l00
2019-03-20 23:27
and with a fake consumer, you have too pacts to obey. one is the real, one is the one you are testing

matt.fellows
2019-03-20 23:28
I?m not sure what you mean? Pact is not a CI/CD tool, but is designed fit _within_ them.

matt.fellows
2019-03-20 23:28
as for the fake consumer, you would delete it as soon as a real one comes on board

evan_l00
2019-03-20 23:29
I mean other libraries/framework also designed fit within them

evan_l00
2019-03-20 23:29
Yeah. Deleting the fake would be the solution.

matt.fellows
2019-03-20 23:30
it just prepares you for when a consumer is ready, rather than you having to setup the process to fetch and verify consumer pacts, integrate the ?can-i-deploy? tool etc. only after a consumer comes on board.

evan_l00
2019-03-20 23:32
I just struggle with why I need to write unit test, api test and contract test. If the API test cover the change, how can the provider break the contracts set by API test. An example about why the pact/contract test rescue would be very appreciated

evan_l00
2019-03-20 23:33
When we do API test, we actually set up contracts between consumer and provider. If the adding change in the provider pass the API test, how can he breaks the contract set up by the API test?

matt.fellows
2019-03-20 23:40
> how can the provider break the contracts set by API test Because the provider is free to change the contract, and then validate that the (new) contract is satisfied by its own testing > When we do API test, we actually set up contracts between consumer and provider How do you do this now? > If the adding change in the provider pass the API test, how can he breaks the contract set up by the API test? don?t also forget that the _consumer_ is a key part of this, and they may inadvertently get out of sync also > I just struggle with why I need to write unit test, api test and contract test Even if you assumed that you had the right level of coverage, traditional e2e testing that ensures they _do_ work together, is slow, fragile, hard to maintain and hard to debug. Contract tests let you test each component in isolation, whilst guaranteeing that they are still compatible

abubics
2019-03-20 23:42
Basically, contract testing like this is further towards the bottom of the testing pyramid, rather than e2e and functional tests that: - have many moving parts, - are slower to run, and - are inherently more flaky

abubics
2019-03-20 23:43
so you can focus on faster feedback, and smaller tests :ok_hand:

abubics
2019-03-20 23:44
Contract testing like this also decouples the consumer and provider. This helps you debug quicker, because you find out which side broke the contract at the start of the test failure, instead of through your own investigation :slightly_smiling_face:

abubics
2019-03-20 23:44
Then you can decide which version of the contract is correct (new or old)

evan_l00
2019-03-20 23:45
@matt.fellows thank you very much! As for "How do you do this now", when we do API test, we definitely assume that provider gives certain responses. And the consumer will work with these responses. Later when I change provider, if I pass the API-test, it means that the consumer could work as before because the certain responses still exists

abubics
2019-03-20 23:45
Because of that, you can also ensure that you only deploy backwards-compatible contract changes

abubics
2019-03-20 23:46
So, the contract is the set of matching interfaces, not a specification artifact?

evan_l00
2019-03-20 23:47
Could you give an example that with API-test, there is something will be broke?

evan_l00
2019-03-20 23:51
I have read DIUS/pact-workshop-js 's example. In the step 3 or 4 says that http://Pact.io to rescue. But I see that the consumer will fail because it does not follow the API that the provider gives instead consumer test the API response based on its imagination.

abubics
2019-03-20 23:55
that's the "consumer-driven" part :slightly_smiling_face:


abubics
2019-03-21 00:00
You need to make a philosophy shift for Pact to give you a benefit. Have you read anything about consumer-driven vs provider-driven APIs? e.g. https://docs.pact.io/#consumer-driven-contracts

abubics
2019-03-21 00:01
A large part of the value of making the API design consumer-driven is that you usually don't know what your consumers need, or how they want to interact with any API you're building.

abubics
2019-03-21 00:03
Oftentimes, you'll have many different consumers, with slightly different needs and use cases. e.g. They won't all use all of the API endpoints. You can write smaller test suites for each consumer, and granularly find out if API changes will break individual consumers.

abubics
2019-03-21 00:04
Then you can talk to those teams and find out why they want to use the API in that way, and either accommodate them, or get them to accommodate your API design.

abubics
2019-03-21 00:04
Pact doesn't replace having conversations between teams, but it can help you have better conversations with the right people :slightly_smiling_face:

evan_l00
2019-03-21 00:11
I get it that it can avoid a lot of communication and negotiation between teams

abubics
2019-03-21 00:11
nono, it's meant to facilitate communication & shared understanding

abubics
2019-03-21 00:12
(but higher quality comms)

evan_l00
2019-03-21 00:15
Thank you @abubics I'll try to figure out left parts with my coding experience grows

abubics
2019-03-21 00:18
There are some good talks and blog posts about it, so let us know if you get stuck again :slightly_smiling_face:

matt.fellows
2019-03-21 00:18
I?d recommend the Atlassian talk, they have nice animations and talk about how they use it with swagger

yousafn
2019-03-21 00:21
^ this. that talk is brilliant. It definitely a philosophical shift into the world of CDC, it should be called collaboration driven contract testing however. I see it as a provider now has a view as to how the consumer is using their service, and exactly what they use, rather than just a load of requests. Provider can put out a new release without breaking all their clients. Without CDC, providers have no view until they put out a release and get broken consumers on the phone, or you have painful integration testing phases where everyone needs to line up at the same time.

evan_l00
2019-03-21 00:22
Thank you all. I google them and read them. If I still get question, I'll will bother you again.


krzysztof.stepniak
2019-03-26 09:38
Hi, guys do you support in stateHandlers async functions?

matt.fellows
2019-03-26 09:52
Yes, they accept promises. They must be a promise, in fact

krzysztof.stepniak
2019-03-26 10:08
Ok, I handled it.

krzysztof.stepniak
2019-03-26 10:11
how should I use `providerStatesSetupUrl`. I can?t find any useful information. Where should it point?

matt.fellows
2019-03-26 10:22
what docs are you looking at?

matt.fellows
2019-03-26 10:23
that field is deprecated in favour of the field you just mentioned (i.e. `stateHandlers` is the new `providerStatesSetupUrl`)


krzysztof.stepniak
2019-03-26 10:31
also I have warning after executing tests: `WARN: Skipping set up for provider state 'Project in db' for consumer 'spaces-web' as there is no --provider-states-setup-url specified.`

matt.fellows
2019-03-26 10:43
how are you running the tests? If you?re using Pact JS, you don?t need to manually run that verifier

krzysztof.stepniak
2019-03-26 10:47
well im using mocha `"provider:pact": "./node_modules/.bin/mocha pact/provider/*.test.js"`

krzysztof.stepniak
2019-03-26 10:48
and yes I am using Pact JS

matt.fellows
2019-03-26 10:48
can you please share your verification code? You shouldn?t be getting that ?skipping?? message

matt.fellows
2019-03-26 10:48
also, as importantly, what?s the version of Pact you?re using?

krzysztof.stepniak
2019-03-26 10:49
?@pact-foundation/pact?: ?^7.3.0", ?@pact-foundation/pact-node?: ?^6.21.4",

krzysztof.stepniak
2019-03-26 10:58
btw. your HAL browser is dead?

bethskurrie
2019-03-26 10:59
Is it?

krzysztof.stepniak
2019-03-26 10:59
i can?t get in API version

krzysztof.stepniak
2019-03-26 10:59
404 everywhere

bethskurrie
2019-03-26 11:02
Thank you for letting us know. I will fix this asap.

matt.fellows
2019-03-26 11:05
`return await new Verifier().verifyProvider(opts);`

matt.fellows
2019-03-26 11:05
the await is superflous here.

matt.fellows
2019-03-26 11:06
Also not that `customProviderHeaders` is evaluated at compile time, so the value _will not change throughout the tests_

bethskurrie
2019-03-26 11:07
Have to wake up all the build nodes :stuck_out_tongue: It's late here so they've all gone to sleep.


matt.fellows
2019-03-26 11:13
oh, you need to update to version 8.x.x - stateHandlers is not in v7

krzysztof.stepniak
2019-03-26 11:43
Ok, I?ll update it. Thanks once again Randy.

matt.fellows
2019-03-26 11:51
hehe

bethskurrie
2019-03-26 11:56
Hal browser is back. Thanks @krzysztof.stepniak

krzysztof.stepniak
2019-03-26 11:56
thanks

krzysztof.stepniak
2019-03-26 13:44
I have one more question when you awake. I have such warn: `WARN: pact@8.0.5/50601 on MacBook-Pro-krzysiek.local: No state handler found for "Project in db", ignorning` Inspite of spelling bug, I have declared state but it is ignoring it but test works fine

krzysztof.stepniak
2019-03-26 13:44
¯\_(?)_/¯

rjmcguinness
2019-03-26 17:04
Hi all, Do you have any recommendations for dealing with matching arrays, particularly nested arrays? For example, I have a payload object with a property `options` which is an array of objects each of which have a property `data` which is an array, see below. ```const dummyPayload = { options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], }, {name: 'option name 2, data: ['sub option 1', 'sub option 2']}, ...repeating on and on ], };``` The below works, but is quite hard to read. This is a simplified example, and some of our responses have deeper nesting. ```const dummyResponsePact = Matchers.somethingLike({ options: Matchers.eachLike({ ...dummyPayload.options, data: Matchers.eachLike(dummyPayload.options[0].data[0]), }), });``` Without the `eachLike` matcher the provider tests fail with a variation of: `Actual array is too long and should not contain a Hash at $.options[1].data[1]` because the provider is doing an exact comparison between the objects (including length). The number of items the provider responds with in either array is variable because it comes from test db data.

matt.fellows
2019-03-26 20:34
I'm not sure it's an actual function assignment there, might want to expand it to make sure the value is a function that returns a promise, and not the value that function returns

matt.fellows
2019-03-26 20:35
I think the framework might be detecting that it's not a function and bails iut

matt.fellows
2019-03-26 20:37
`stateHandlers: {'Project in db': await states.projectInDb(token)}` should be something like `stateHandlers: {'Project in db': () => states.projectInDb(token)}`

krzysztof.stepniak
2019-03-27 07:43
ok, stack dissapeared but when promise is resolved? Since `projectInDb(token)` is async function. Is it resolved before proper tests?

matt.fellows
2019-03-27 07:46
the framework will wait for the promise to resolve. It wants a promise, not a value

krzysztof.stepniak
2019-03-27 07:47
ok, now i understand

matt.fellows
2019-03-27 07:47
Look at the e2e test example in the repository if you need a working example

krzysztof.stepniak
2019-03-27 07:47
m?kay

matt.fellows
2019-03-27 08:23
:thumbsup:

paras.vora
2019-03-27 08:34
has joined #pact-js

krzysztof.stepniak
2019-03-27 15:33
Ok guys I know I am harrasing you alot lately but I have another problem. This time with jenkins. Long story short on localhost pact tests works fine but on jenkins I have such thing on consumer side:

matt.fellows
2019-03-27 19:37
That doesn?t look to relate to Jenkins specifically, what is the runtime environment? If Alpine, do some searches as their are extra things you?ll need to make it work

vitaliy.grigoruk
2019-03-28 09:06
@krzysztof.stepniak Here: ``` [90m [36mPact Binary Error: /var/lib/jenkins/workspace/Contract tests/platform-e2e-test/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.63.0/lib/ruby/bin/ruby: line 14: tests/platform-e2e-test/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.63.0/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory ``` I?d avoid having spaces in a path. I belive you should just replace a space in ?/Contract tests/?

krzysztof.stepniak
2019-03-28 09:08
I?ll try

krzysztof.stepniak
2019-03-28 09:11
Yep, you were right. Thanks @vitaliy.grigoruk.

vtambourine
2019-03-28 14:01
has joined #pact-js

mboudreau
2019-03-29 01:09
good release that one :wink:

joseph.s.egan
2019-03-30 18:46
has joined #pact-js

krzysztof.stepniak
2019-04-01 07:04
Hi, guys. Have you ever had problem with provider side on jenkins? I struggling with it for two days and I starting to loose any hope wit resolving this issue. Test is setting up but after setting up state above Error shows. Certificates are set in provider side and ssl flag is set on false ( i see them in console log). Do you have any idea where should I look ?

matt.fellows
2019-04-01 07:07
Can you please share your setup and any/all log files. Haven't seen that before

matt.fellows
2019-04-01 07:08
Any reason why you need SSL?

krzysztof.stepniak
2019-04-01 07:11
do you need provider file ?

matt.fellows
2019-04-01 07:11
Well, not necessarily. I need to know as much as possible to help diagnose, so the more the merrier

krzysztof.stepniak
2019-04-01 07:12
btw. on localhost works fine on two different computers

krzysztof.stepniak
2019-04-01 07:13
Provider file

matt.fellows
2019-04-01 07:17
What's the value of providerBaseUrl?

krzysztof.stepniak
2019-04-01 07:19
depends of env but in this case https://api.platform-dev.silvair.com

matt.fellows
2019-04-01 07:23
And you say it works locally?

matt.fellows
2019-04-01 07:24
Are you running in docker or does that host not have the standard can bundle installed?

matt.fellows
2019-04-01 07:24
CA bundle*

krzysztof.stepniak
2019-04-01 07:24
yes, but on localhost connect with my local service

matt.fellows
2019-04-01 07:24
Right. What happens if you point to that host?

krzysztof.stepniak
2019-04-01 07:25
let me try, wait a sec

matt.fellows
2019-04-01 07:27
:+1:

matt.fellows
2019-04-01 07:27
I'm just hoping in a car and will check-in later

matt.fellows
2019-04-01 07:27
We need to know who h specific request at what point is failing.

krzysztof.stepniak
2019-04-01 07:27
well stack like on jenkins -_-?

matt.fellows
2019-04-01 07:28
I'd look to repro locally and go from there

krzysztof.stepniak
2019-04-01 07:28
mkay

matt.fellows
2019-04-01 19:33
Howd you go?

krzysztof.stepniak
2019-04-02 07:49
not good actually

matt.fellows
2019-04-02 07:50
Bugger

krzysztof.stepniak
2019-04-02 07:50
Im not sure why pact asks for localhost `Uncaught Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:http://platform-dev.silvair.com, DNS:*.http://platform-dev.silvair.com`

matt.fellows
2019-04-02 07:50
Any reason why you don't do the provider testing on Jenkins like you do on your workstation - hit localhost?

krzysztof.stepniak
2019-04-02 07:51
it is different server

matt.fellows
2019-04-02 07:51
Why?

matt.fellows
2019-04-02 07:53
What's the contract file look like? Is there a host header in there set to localhost? That could explain why it's failing with a certificate mismatch but hitting the correct server

krzysztof.stepniak
2019-04-02 07:54
Do you want consumer side file or just contract?

matt.fellows
2019-04-02 07:54
Contract is fine. Specifically the interaction that fails if possible

krzysztof.stepniak
2019-04-02 07:55
ok

krzysztof.stepniak
2019-04-02 07:56
here is interaction:

krzysztof.stepniak
2019-04-02 07:59
what i Can see that states are done, but in the beginning of the interaction brokes

matt.fellows
2019-04-02 08:05
Nothing in that other interaction that is a cause for concern

matt.fellows
2019-04-02 08:05
The fact that it works locally is telling

matt.fellows
2019-04-02 08:05
There is something wrong with the Jenkins setup

krzysztof.stepniak
2019-04-02 08:05
naah

krzysztof.stepniak
2019-04-02 08:06
when im trying to start script from my pc against dev server the same error comes up.

matt.fellows
2019-04-02 08:06
Why can't you start up the provider on Jenkins like t you would locally?

krzysztof.stepniak
2019-04-02 08:06
I would need to setup docker with enviroment

matt.fellows
2019-04-02 08:07
How do you change provide states against a remote API?

krzysztof.stepniak
2019-04-02 08:07
Is there any problem with https on verify?

krzysztof.stepniak
2019-04-02 08:08
I didn?t change them

krzysztof.stepniak
2019-04-02 08:08
what I see in debug is that provider state is creating on localhost

krzysztof.stepniak
2019-04-02 08:09

krzysztof.stepniak
2019-04-02 08:11
but it use client to make request to dev db and create project

matt.fellows
2019-04-02 08:11
Sorry I'm just driving home but I might have an idea as to what it could be

krzysztof.stepniak
2019-04-02 08:12
ok, drive safely

matt.fellows
2019-04-02 11:52
Thanks. So I think we don't fully support proxying remote APIs (it's very much not a standard thing to do). If you don't mind submitting an issue that would be great. I'll take a look tomorrow to see if it's an easy fix

krzysztof.stepniak
2019-04-02 11:56
ok

matt.fellows
2019-04-02 19:35
Thx

laxmi.somni
2019-04-03 14:10
has joined #pact-js

adamgreen
2019-04-03 14:27
Apologies for the late reply Matt, i've not had much joy in the casting, being a bit new to TS/JS as I am. I'll wait and see how my Issue gets along in the mean time, hopefully it's an easy fix. Thanks again for the help :+1:

paras.vora
2019-04-04 12:51
Hello, there is a jwt authorization implemented in my project. Can anyone please help with any working code repo to deal with this scenario? Note - the life of the bearer token is only 3 mins.


paras.vora
2019-04-04 12:52
However, I am unable to figure out what would be the value of the `${token}` variable ?

vitaliy.grigoruk
2019-04-04 20:22
as people are normally running provider verification from within production codebase, it shouldn?t be an issue to call some method that generates a valid JWT token.

matt.fellows
2019-04-04 23:07
@paras.vora request filters lets you amend the request to the provider during provider side verification. How are you sending the JWT to the provider now? e.g. is it an authorization header?

matt.fellows
2019-04-04 23:08
whatever mechanism, request filters allow you to actually modify the entire request object - fields, headers etc.. So your job is to create a valid JWT (whether a ?real? one or a valid but fake one as @vitaliy.grigoruk notes) and then add it.

paras.vora
2019-04-05 07:03
@matt.fellows I have no way to generate a valid token & even I generate it, the token validation service wont be available for authorization at the time provider test is running.

matt.fellows
2019-04-05 10:06
So my suggestion is to stub the auth service during provider verification, so the contents of the JWT can be stored in the pact and there is no need for using those more complicated features

paras.vora
2019-04-05 10:32
@matt.fellows the authorization would fail anyways as the life of the token is only 3 mins.

matt.fellows
2019-04-05 10:35
So what can we do?

matt.fellows
2019-04-05 10:36
Why can't you generate a valid token?

matt.fellows
2019-04-05 10:41
If you can't generate a valid token, how could you ever test it? Can't you stub the auth service and send a dummy token?

paras.vora
2019-04-05 11:12
You mean mocking the authorization service

paras.vora
2019-04-05 11:12
?

vitaliy.grigoruk
2019-04-05 11:37
rather stubbing than mocking

matt.fellows
2019-04-05 11:55
But yes, whatever is easiest for you.

matt.fellows
2019-04-05 11:57
You want to test each component in isolation. If your provider has downstream dependencies, stub them out during testing and then apply the same contract testing process to them. Repeat this process until you get to the end of dependency chain

matt.fellows
2019-04-05 11:57
Voila, you have contract tests for your whole app and you don't have to setup an e2e environment to test it

mo.balghonaim
2019-04-08 00:45
has joined #pact-js

mo.balghonaim
2019-04-08 00:48
Hello, I'm trying to debug a failing provider verification. Is there a way to see outgoing request? I'm getting this test failure output:

mo.balghonaim
2019-04-08 02:23
I noticed that the `providerBaseUrl` I provided in the options passed to `verifyProvider()` has been overwritten with 'localhost', which is what responds with '503'. Does this proxy server make the actual call to my original `providerBaseUrl`?

asad
2019-04-08 07:45
Hi i am getting this `ERROR: The process "12956" not found.` issue on windows , when i run my pact consumer/provider test ``` [2019-04-08T07:33:55.650Z] INFO: pact-node@6.21.5/20088 on DESKTOP-KOB10PR: Created 'standalone\win32-1.63.0\bin\pact-mock-service.bat service --consumer 'afterfx' --pact_dir 'C:\xampp\htdocs\afterfx-service\tests\pacts' --host '127.0.0.1' --log 'C:\xampp\htdocs\afterfx-service\tests\pact logs\pact-tests.log' --pact-file-write-mode 'update' --port '8991' --provider 'prestac' --pact_specification_version '2'' process with PID: 12956 ERROR: The process "12956" not found. ``` weird thing is its working on other project on same device, it was working for above project too but because of some error jest did't terminated the test process and so i did `ctr+c` to end it and the error showed up afterwards.

matt.fellows
2019-04-08 08:46
I think a process might be hanging around.

matt.fellows
2019-04-08 08:46
Check to see if there are any dangling Ruby or Node processes

asad
2019-04-08 09:55
ok thank will look into it

matt.fellows
2019-04-08 11:25
yes, that is the case

matt.fellows
2019-04-08 11:26
you might get some more data by turning the log level up to ?DEBUG? or better, but we may need more instrumentation to help with it.

matt.fellows
2019-04-08 11:26
Is the broker URL external to the local host / running a cert?

mo.balghonaim
2019-04-08 20:03
Hello, it seems like I'm missing a required header or something, because I tried it with a different API and it seems to work. I'll re-ask the question if it appears to be an issue with the framework. Thanks!

simon.nizov
2019-04-10 08:47
has joined #pact-js

rjmcguinness
2019-04-10 10:32
Do you have any recommendations for matching arrays, particularly nested arrays? For example, I have a payload object with a property `options` which is an array of objects each of which have an array `data` as a property, see below. ```const dummyPayload = { options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], }, {name: 'option name 2, data: ['sub option 1', 'sub option 2']}, ...repeating on and on ], };``` The below works, but is quite hard to read. This is a simplified example, and some of our responses have deeper nesting. ```const dummyResponsePact = Matchers.somethingLike({ options: Matchers.eachLike({ ...dummyPayload.options, data: Matchers.eachLike(dummyPayload.options[0].data[0]), }), });``` Without the `eachLike` matcher the provider tests fail with a variation of: `Actual array is too long and should not contain a Hash at $.options[1].data[1]` because the provider is doing an exact comparison between the objects (including length).

simon.nizov
2019-04-10 11:25
@simon.nizov has left the channel

andrew.nicholson
2019-04-11 19:36
has joined #pact-js

rjmcguinness
2019-04-12 08:27
@matt.fellows are you able to answer this? I feel like this isn?t the way I should be doing things, to just provide a ?1 or more of this item in the array? matcher

matt.fellows
2019-04-12 08:50
Will take a look at bit later. Happy to help (just cooking tea :grinning:)

rjmcguinness
2019-04-12 10:30
Thanks :slightly_smiling_face:

matt.fellows
2019-04-12 10:59
Have you tried simply ``` like({ options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], } ], }) ``` Matchers should propagate down to nested arrays, so you shouldn?t need to repeat yourself

rjmcguinness
2019-04-12 11:00
like() is an alias to somethingLike, correct? I tried this but still need the eachLike to say min 1 from the array/matching an item in the array

matt.fellows
2019-04-12 11:02
what is it doing instead?

rjmcguinness
2019-04-12 11:05
It spits out the pact as expected, just without the array matching rules. So our provider has to have the same amount of items in that array in their fixtures for it to validate

matt.fellows
2019-04-12 11:05
hmm I?ll double check this behaviour, it sounds suspicious

rjmcguinness
2019-04-12 11:14
I would think this is expected behaviour as per https://github.com/pact-foundation/pact-js#match-based-on-arrays These are the matchers that eachLike produces: ``` "$.body.propertyA[*].something": { "min": 1 }, "$.body.propertyA[*].something[*].*": { "match": "type" }, ``` Without eachLike we would only have: ``` "$.body": { "match": "type" }, ``` which matches everything recursively, but requires the response?s arrays to have the same lengths as those in the pact

matt.fellows
2019-04-12 11:18
Yep. It?s the verification side I was hoping that would propagate, but I guess not

matt.fellows
2019-04-12 11:19
I?m checking with maintainers, it would certainly be nice if we could have a matcher that did this

matt.fellows
2019-04-12 13:33
Np

vitaliy.grigoruk
2019-04-15 10:31
Hey @matt.fellows. What do you think about ?un-deprecating? `providerStatesSetupUrl` (so either `providerStatesSetupUrl` or `handlers` needs to be passed to pact verifier, but not both)? I know that a new way to setup provider state is to specify state handlers. This will work for majority of projects I guess. In a project I?m working on right now we need to ensure each pair of `state setup + test request` run within `sequelize` transaction (so, DB is left untouched after test run). We managed to implement a desired setup using pact v7 (basically, we are running our own proxy server, heavily inspired by your work on `handlers`). Now, pact v8 is released with its own proxy for state handling and v7 doesn?t get security updates anymore. We would like to run on the latest version, but we can?t as our implementation of state + transaction handling won?t work with pact v8. The simplest solution I see is to still allow people to use `providerStatesSetupUrl` if `requestFilters` and `stateHandlers` are not enough. I?ll be happy to make a PR if you?re ok with the proposal

asite-rshah
2019-04-15 11:22
has joined #pact-js

matt.fellows
2019-04-15 20:52
I saw your PR, I?ll answer there. I need to think about it, but thanks for the feedback. Perhaps others have the need also.

martin.green
2019-04-16 15:47
has joined #pact-js

marc
2019-04-17 13:28
has joined #pact-js

nodkane12
2019-04-17 14:23
has joined #pact-js

albertot
2019-04-18 16:35
has joined #pact-js

albertot
2019-04-18 16:47
(Moved to #general)

mitchell.davis
2019-04-23 06:51
has joined #pact-js

jjlehva
2019-04-25 12:37
hey, should I use `pact-js` or `pact-node`? What is the difference?

vitaliy.grigoruk
2019-04-25 12:40
use pact-js (it uses pact-node as a dependency)

jjlehva
2019-04-25 12:40
ok, thanks :+1:

jjlehva
2019-04-25 12:41
is there some purpose of having both of them? :smile:

vitaliy.grigoruk
2019-04-25 12:46
long term goal AFAIK is to get rid of pact-node

vitaliy.grigoruk
2019-04-25 12:46
pact-node is a wrapper for pact-ruby-standalone binaries

vitaliy.grigoruk
2019-04-25 12:47
while pact-js is a DSL to use in your JS / TS CDC test suites

vitaliy.grigoruk
2019-04-25 12:47
Hey folks, could somebody explain me the difference between `tags` and `consumerVersionTag` here? https://github.com/pact-foundation/pact-js/blob/master/src/dsl/verifier.ts#L40-L45

vitaliy.grigoruk
2019-04-25 12:54
I?m trying to figure out the right setup for triggering provider verification CI job for a recently updated consumer contract. I?m tagging my contracts with branch names and versioning them with ?git commit sha?. My pact broker webhook passes contract tag (e.g. `master`) when it triggers provider contract verification CI job. This works well with 1 consumer, but doesn?t work so well if I have 2+ consumers (as I?ll run contract verification for all consumers). Ideally, I?d like to be able to pass consumer name, but such option doesn?t exist.

vitaliy.grigoruk
2019-04-26 10:47
ok, after some investigation I found out that `tags` are not used at all in `pact-provider-verifier` and `consumerVersionTag` actually can be an array. Here is a PR to fix this in pact-node: https://github.com/pact-foundation/pact-node/pull/155 I?ll appreciate fast feedback on this one.

matt.fellows
2019-04-26 13:21
Thanks for all of your digging / support. The changes merged are now released (8.2.2). I?ll wait for review of this change before sending it out.

ian.mcwilliams
2019-04-29 12:05
has joined #pact-js

ian.mcwilliams
2019-04-29 12:07
hey all :wave: i am setting up a kafka test and using `messagePact` `.withContent`; so the object from there is passed into the handler specified in `.verify(handlerFunction)`

ian.mcwilliams
2019-04-29 12:09
when the object is passed to the handler it is wrapped in `contents` (eg `{ contents: [object] }`) - i don't think it's right to expect the handler to deconstruct the contents, does anyone have a way of managing this more cleanly?

ian.mcwilliams
2019-04-29 12:11
```describe('receive record', () => { it('accepts a valid record', async () => { return ( messagePact .expectsToReceive('a valid record') .withContent({ data: { feed_date: term({generate: "2019-01-01", matcher: "^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$"}), item: { record_id: 123, record_name: like('someRecord') } } }) .verify(handlerFunction) ); }); });```

paras.vora
2019-04-29 12:50
Hello, my Chrome is getting crashed frequently upon running the tests frequently.

paras.vora
2019-04-29 12:51
Please check the error....

matt.fellows
2019-04-29 12:53
What has this got to do with Pact, exactly?

matt.fellows
2019-04-29 15:42
There are a couple of helpers that wrap this for you e.g. `synchronousBodyHandler`

matt.fellows
2019-04-29 15:42
You wouldn?t want your domain code handling this, no

matt.fellows
2019-04-29 15:43
It?s provided to allow access to the metadata, which we?ll eventually (in JS at least) validate

pascal.wilbrink
2019-04-29 20:35
has joined #pact-js

pascal.wilbrink
2019-04-29 20:37
Hi all, it seems that my karma config is not setup correctly. But i'm using the same setup as all the examples i can find (I think). The pact-mock-server is starting correctly, but none of my tests are ran. Did this happen to anyone else? My setup: ``` const path = require('path') module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular-devkit/build-angular', 'pact'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('@angular-devkit/build-angular/plugins/karma'), require('@pact-foundation/karma-pact') ], client: { clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { dir: require('path').join(__dirname, '../../coverage/movies-lib'), reports: ['html', 'lcovonly'], fixWebpackSourcePaths: true }, files: [ 'node_modules/@pact-foundation/pact-web/pact-web.js', ], reporters: ['progress', 'kjhtml'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, restartOnFileChange: false, pact: [{ cors: true, port: 1234, dir: "pacts/", spec: 2, log: path.resolve(process.cwd(), 'logs', 'pact.log') }], proxies: { '/api/': 'http://localhost:1234/' } }); }; ```

pascal.wilbrink
2019-04-29 20:41
when i run the test (ng test --project movies-lib) i see this: ```29 04 2019 22:37:23.668:INFO [pact]: Pact Mock Server running on port: 1234```

pascal.wilbrink
2019-04-29 20:50
it's working now, i had to delete my node_modules and re-install them again

paras.vora
2019-04-30 06:49
@matt.fellows Wrong window. Sorry.

ian.mcwilliams
2019-04-30 08:03
I see - yes that's worked, thanks @matt.fellows :+1:

jjlehva
2019-04-30 09:54
has anyone been able to get `pact-js` working with `jest` ? Jest is always finishing before the `afterAll` part where I call the `finalize()` etc. Something really strange going on. I am about to give up :sweat_smile:

jjlehva
2019-04-30 09:55
I got pact to properly create the contracts but Jest still just prints errors such as `Cannot log after tests are done. Did you forget to wait for something async in your test?`

yousafn
2019-04-30 10:03
yeah i run all my pact tests with jest

jjlehva
2019-04-30 10:03
and I am also getting this every time `setup` and `finalize` are called: ``` console.warn node_modules/request-promise/node_modules/bluebird/js/release/debuggability.js:873 Unhandled rejection RequestError: Error: connect ECONNREFUSED 127.0.0.1:6060 at new RequestError (/Users/user/workspace/project/node_modules/request-promise-core/lib/errors.js:14:15) at Request.plumbing.callback (/Users/user/workspace/project/node_modules/request-promise-core/lib/plumbing.js:87:29) at Request.RP$callback [as _callback] (/Users/user/workspace/project/node_modules/request-promise-core/lib/plumbing.js:46:31) at self.callback (/Users/user/workspace/project/node_modules/request/request.js:185:22) at Request.emit (events.js:189:13) at Request.Object.<anonymous>.Request.onRequestError (/Users/user/workspace/project/node_modules/request/request.js:877:8) at ClientRequest.emit (events.js:189:13) at Socket.socketErrorListener (_http_client.js:392:9) at Socket.emit (events.js:189:13) at emitErrorNT (internal/streams/destroy.js:82:8) at emitErrorAndCloseNT (internal/streams/destroy.js:50:3) at process._tickCallback (internal/process/next_tick.js:63:19) ```


jjlehva
2019-04-30 10:04
cool! thanks, I?ll have a look

yousafn
2019-04-30 10:05
feel free to share any example code and we can have a look at it


jjlehva
2019-04-30 10:10
I had a look at this but I didn?t get much out of it

jjlehva
2019-04-30 10:11
I didn?t really like the idea of setting things to the global scope etc. I tried the approach though and had the same result :smile:

jjlehva
2019-04-30 12:50
so I wasn?t able to figure out why the tests were not working properly with Jest. No idea really. I had two of my colleagues also trying to figure it out with no luck

jjlehva
2019-04-30 12:51
I ended up also refactoring the test to a simple node script that runs everything in a promise chain in the correct order. That worked OK

jjlehva
2019-04-30 12:52
after that I tried using nyc and mocha. So I simply changed the `afterAll` to `after` and `beforeAll` to `before`. And surprisingly the test just works :shrug:

jjlehva
2019-04-30 12:53
so `node` and `mocha` are ok but `jest` just fails to those `ECONNREFUSED` and `Cannot log after tests are done` errors

krzysztof.stepniak
2019-04-30 12:56
@yousafn did you just post working example with sending file on github?

yousafn
2019-04-30 12:57
I did chap

yousafn
2019-04-30 12:57
just had to get it working for a client at work, so thought I would pass back my learnings!

krzysztof.stepniak
2019-04-30 12:59
Cool, thanks. I?ll try it in node :stuck_out_tongue:.

yousafn
2019-04-30 13:05
gimme two secs and ill post up an edit

krzysztof.stepniak
2019-04-30 13:06
Sure

yousafn
2019-04-30 13:11
just tested this now so should be good to go, updated comment on your issue too

ian.mcwilliams
2019-04-30 14:54
aren't beforeAll and afterAll jasmine rather than jest?

rjmcguinness
2019-04-30 15:10
They?re in both

abubics
2019-04-30 22:58
Last time I tried, Jest didn't properly nest befores and afters (but mocha does)... So I usually fall back to mocha for sanity :sweat_smile:

bethskurrie
2019-04-30 23:21
I had a feeling @tjones had done a pact-jest "plugin", but only in a private project.

matt.fellows
2019-04-30 23:27
He just has his way of using (DRYing) it, from memory. It?s probably documented in a GitHub issue/enhancement somewhere

tjones
2019-04-30 23:41
Yep, I wrote a small wrapper that gives a DRYer and slightly nicer (in my opinion) DSL.

tjones
2019-04-30 23:41
I *think* it?s on an issue in pact-js

tjones
2019-04-30 23:41
And if not, I can dig it up and post it here

bethskurrie
2019-04-30 23:41
Hello Tim! We miss you!

tjones
2019-04-30 23:41
I?ve been planning to make it a module

tjones
2019-04-30 23:41
Hello! I miss you all too!

tjones
2019-04-30 23:42
I?ll be back next week. I think? How does time work?

tjones
2019-04-30 23:42
The 8th

bethskurrie
2019-04-30 23:42
Woot!

tjones
2019-04-30 23:49
Scrolling up- I?ve had no issues with running pact through Jest, but it?s worth noting that Jest runs suites in parallel by default. It?s easiest to turn this off, or write a wrapper so you don?t have collisions

tjones
2019-04-30 23:49
(If you have multiple pact suites)

tjones
2019-04-30 23:50
Also: I find that *not* running Jest tests in parallel results in faster execution time on my machine (recent MacBook Pro). I haven?t looked in to why this is.


tjones
2019-04-30 23:54
I think I have a more recent version that is better. This version can result in overwriting log files if you have multiple pact suites

tjones
2019-04-30 23:55
It?s hard to solve that without having opinions on what does and doesn?t go in a test suite (eg, should each provider/consumer combo be only one test suite?).

tjones
2019-04-30 23:59
I?d really like to improve the wrapper and release a module that you can import and not have to write so much boilerplate, but I?m not yet sold on where to draw the line on conventions that are generally useful vs what is useful if you are me (which I assume you aren?t)

ian.mcwilliams
2019-05-01 08:19
i'm now struggling to debug what seems like quite a general message, i've been through and double checked everything and it all seems to be working - in fact it works fine running normally, it's failing when i try to run it in a container (trying to add kafka tests to CI) - the container itself appears to be handling things just fine

ian.mcwilliams
2019-05-01 08:19
``` Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout. 16 | 17 | describe('receive item', () => { > 18 | it('accepts a valid item', async () => { | ^ 19 | return (messagePact 20 | .expectsToReceive('a valid item record') at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:92:20) at http://Suite.it (__tests__/contract/kafka-client.test.pact.js:18:3) at Object.describe (__tests__/contract/kafka-client.test.pact.js:17:1)```

ian.mcwilliams
2019-05-01 08:24
the verify method in messagePact is returning a Promise

ian.mcwilliams
2019-05-01 08:24
```.verify(synchronousBodyHandler(handlerFunction))```

ian.mcwilliams
2019-05-01 08:25
the handlerFunction itself is returning a raw object

matt.fellows
2019-05-01 08:38
Which part is running in the container? (the whole lot?) I?d check a couple of things: 1. Ports / expose (running on `127.0.0.1` will prevent it from being exposed out of the container) 2. If `./node_modules` is being shared, there might be a binary incompatibility if your host is a different os/arch (e.g. linux docker image with Mac OSX host). Make sure to `npm i` in the container to ensure native deps

ian.mcwilliams
2019-05-01 09:38
yeah, the whole thing is running in container, no ports need to be exposed; i'm seeing output straight from stdout from within the container

ian.mcwilliams
2019-05-01 09:40
a volume is being shared between host machine and container so i can get to my code from within the container; but i removed node_modules and ran yarn install from inside the container - it's part of the build command: `docker-compose run backend sh -c 'yarn && yarn db:rebuild && yarn test:contract'`

ian.mcwilliams
2019-05-01 09:41
to remove node_modules i ran it as:

ian.mcwilliams
2019-05-01 09:41
```docker-compose run backend sh -c 'rm -rf node_modules && yarn && yarn db:rebuild && yarn test:contract' ```

ian.mcwilliams
2019-05-01 10:26
i'm looking at this with our devops lead, it seems like there's a difference in the config being called - it's test in local, dev in the container, so perhaps this is the root of the issue

matt.fellows
2019-05-01 11:12
ok interesting

matt.fellows
2019-05-01 11:12
If you have an example I can use to repro I?d happily take a look for you

matt.fellows
2019-05-01 11:12
Unfortunately a bit hard going off the detaili so far

ian.mcwilliams
2019-05-01 11:23
have lined up the local vs container and no change, it passes locally but fails in container

ian.mcwilliams
2019-05-01 11:23
i'll see what i can do to provide a concrete example

matt.fellows
2019-05-01 11:25
thanks

matt.fellows
2019-05-01 11:25
sorry hear - what a pain!

matt.fellows
2019-05-01 11:25
oh, what?s the container image?

matt.fellows
2019-05-01 11:25
(sorry I?ve been at a conference all week, so my responses are often bursty and from a mobile)

matt.fellows
2019-05-01 11:26
s/been/am


ian.mcwilliams
2019-05-01 11:33
we've switched from alpine previously as it wouldn't run ruby

ian.mcwilliams
2019-05-01 11:33
now using node:10-slim

ian.mcwilliams
2019-05-01 11:33
here's a stripped down version of the test file - this has the same result (passes local, fails container)

matt.fellows
2019-05-01 11:37
perfect thanks - I?ll look shortyl

matt.fellows
2019-05-01 11:37
regarding alpine, see above for how to make it work (tl;dr - needs bash)

andrewspinks
2019-05-01 23:18
has joined #pact-js

jjlehva
2019-05-02 07:46
is it not possible to have a matcher for values which can be either `string` or `null` ? Or `number` or `null` ?


matt.fellows
2019-05-02 07:47
It's not, see the FAQ at doc'http://s.pact.io as to why

matt.fellows
2019-05-02 07:47
:point_up::laughing:

jjlehva
2019-05-02 07:55
Ok, makes sense. Thanks for the fast response :smile:

matt.fellows
2019-05-02 07:55
:ok_hand:

jjlehva
2019-05-02 07:56
I am just about to finish writing my thesis about consumer-driven contract testing and I still managed to miss / forget about that :face_with_rolling_eyes:

matt.fellows
2019-05-02 07:57
Hehe np

yousafn
2019-05-02 11:12
Hey Tim, I started work on publishing an npm module, based on your initial proposal, as we needed to cut down on the boilerplate stuff we are writing at work as the amount of services we are covering keeps growing Adapter is here https://github.com/YOU54F/jest-pact A repo using it https://github.com/YOU54F/jest-pact-typescript I am building up a little toolset that we can use across our work projects, as we have common pact scripts used in all repos and it?s becoming a pain to maintain them all!

matt.fellows
2019-05-02 11:49
did you have the docker container for that too?

matt.fellows
2019-05-02 12:09
package.json ``` { "name": "ian", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "jest" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@pact-foundation/pact": "^8.2.2", "jest": "^24.7.1" } } ``` Dockerfile: ``` FROM node:8-alpine RUN apk add --no-cache --virtual build-dependencies build-base RUN apk --no-cache add ca-certificates wget bash \ && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \ && apk add glibc-2.29-r0.apk WORKDIR /app COPY package*.json /app/ RUN npm install COPY . /app/ RUN npm t ``` Run the following: `docker build .`

matt.fellows
2019-05-02 12:09
works ok for me: ``` > jest [2019-05-02T12:07:03.905Z] INFO: pact@8.2.2/15 on a08d3744bcf1: Verifying message [2019-05-02T12:07:03.909Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: Creating Message [2019-05-02T12:07:03.910Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: Creating message pact [2019-05-02T12:07:03.923Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: Created './standalone/linux-x64-1.64.1/bin/pact-message 'update' '{"description":"a valid item record","contents":{"data":{"dummy":1}}}' --consumer 'some-consumer' --pact_dir '/app/__tests__/pacts' --provider 'some-provider' --pact_specification_version '3'' process with PID: 45 PASS __tests__/kafka-client.test.pact.js receive item ? accepts a valid item (632ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 2.803s Ran all test suites. [2019-05-02T12:07:04.531Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: ```

matt.fellows
2019-05-02 12:12
Working repo


joostvanwollingen
2019-05-02 13:00
has joined #pact-js

dagarwal
2019-05-02 15:35
Hi , I have generated json using pact test but then request is giving me 404 , can you point me to what am i missing here ? ==> Received request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sort?: [?desc?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sortBy?: [?Last_Modified?], ?status?: [?failed?, ?cancelled?]}), headers: Some({?User-Agent?: ?Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36?, ?Access-Control-Request-Headers?: ?content-type?, ?Host?: ?127.0.0.1:18159?, ?Access-Control-Request-Method?: ?GET?, ?Origin?: ?http://localhost:4200?, ?Connection?: ?keep-alive?, ?Accept-Encoding?: ?gzip, deflate, br?, ?Accept?: ?*/*?, ?Referer?: ?http://localhost:4200/fmp/index?, ?Accept-Language?: ?en-US,en;q=0.9"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [INFO] | 15:29:19 [INFO] comparing to expected request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sortBy?: [?Last_Modified?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sort?: [?desc?], ?status?: [?failed?]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {?query?: Category { name: ?query?, rules: {?status[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?criteria[0]?: RuleList { rules: [Regex(?first_load?)], rule_logic: And }, ?sort[0]?: RuleList { rules: [Regex(?desc|asc?)], rule_logic: And }, ?sortBy[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?lastModifiedFrom[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }} }} }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [WARN] No matching request found, sending 404 Not Found flex-usersetting-service | 15:29:19 [INFO]

abubics
2019-05-02 23:54
Nothing obvious to me

abubics
2019-05-02 23:54
the matchers look like it should work ``` ==> Received request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sort?: [?desc?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sortBy?: [?Last_Modified?], ?status?: [?failed?, ?cancelled?]}), headers: Some({?User-Agent?: ?Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36?, ?Access-Control-Request-Headers?: ?content-type?, ?Host?: ?127.0.0.1:18159?, ?Access-Control-Request-Method?: ?GET?, ?Origin?: ?http://localhost:4200?, ?Connection?: ?keep-alive?, ?Accept-Encoding?: ?gzip, deflate, br?, ?Accept?: ?*/*?, ?Referer?: ?http://localhost:4200/fmp/index?, ?Accept-Language?: ?en-US,en;q=0.9"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [INFO] | 15:29:19 [INFO] comparing to expected request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sortBy?: [?Last_Modified?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sort?: [?desc?], ?status?: [?failed?]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: { ?query?: Category { name: ?query?, rules: { ?status[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?criteria[0]?: RuleList { rules: [Regex(?first_load?)], rule_logic: And }, ?sort[0]?: RuleList { rules: [Regex(?desc|asc?)], rule_logic: And }, ?sortBy[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?lastModifiedFrom[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And } } } } }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [WARN] No matching request found, sending 404 Not Found flex-usersetting-service | 15:29:19 [INFO] ```

abubics
2019-05-02 23:54
I'd recommend using the formatting markup to make it easier for people to help you, btw :slightly_smiling_face:

matt.fellows
2019-05-03 01:32
That JSON looks to have AND matchers - did you generate the Pact from a v3 spec (e.g. Java)?

matt.fellows
2019-05-03 01:32
JS does not support the v3 spec yet

dagarwal
2019-05-03 08:12
I generated it with JS v2 spec

dagarwal
2019-05-03 08:12
Can this be the reason ?status?: [?failed?, ?cancellled?] ?

matt.fellows
2019-05-03 08:19
Can you please share the test? Generators and RuleList don't look like things JS can support

matt.fellows
2019-05-03 08:19
Is this a consumer or provider test?

matt.fellows
2019-05-03 08:20
It looks like a library that can deal with Optional types has made this, which is why I think JVM is involved (e.g. Scala or Kotlin)

dagarwal
2019-05-03 08:21
consumer test

dagarwal
2019-05-03 08:21
describe(?Get the user profile?, () => { before(() => provider.addInteraction({ given: ?GET call to get user profile?, uponReceiving: ?Get call for user profile?, withRequest: { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: { lastModifiedFrom: term({ generate: ?24 Apr 2019?, matcher: ?.*? }), sort: term({ generate: ?desc?, matcher: ?desc|asc? }), sortBy: term({ generate: ?Last_Modified?, matcher: ?.*? }), criteria: term({ generate: ?first_load?, matcher: ?first_load? }), status: term({ generate: ?failed?, matcher: ?.*? }) } }, willRespondWith: { status: 200, headers: { ?Access-Control-Request-Headers?: ?content-type?, ?Referer?: ?http://localhost:4200/fmp/index', ?Access-Control-Request-Method?: ?GET? }, body: userProfile } })); it(?should generate data for user profile?, () => request.options(`http://localhost:${PORT}/header/api/user/profile?lastModifiedFrom=24 Apr 2019&sort=desc&sortBy=Last_Modified&criteria=first_load&status=failed`) .set({ Accept: ?application/json? }) .then((response) => { expect(response.statusCode).to.equal(200); }) .catch((err) => { console.log(?Error in generating user profile?, err); })); });

matt.fellows
2019-05-03 08:33
What does `userProfile` look like?

matt.fellows
2019-05-03 08:34
Is this a failure on the consumer or provider test?

dagarwal
2019-05-03 08:35
consumer is generating the json . but when its compared to the provider side ..it fails

dagarwal
2019-05-03 08:35
as the requests are not matched

matt.fellows
2019-05-03 08:37
is the proovider a JVM one?

dagarwal
2019-05-03 08:39
no its also in js .Plus I am using it through pact stub server

matt.fellows
2019-05-03 08:57
Aha! Ok the response we are seeing is coming from rust, that helps

matt.fellows
2019-05-03 08:58
The stub server is rust, just FYI

matt.fellows
2019-05-03 08:58
So your provider is not sending a request to the stub server that it recognises

dagarwal
2019-05-03 08:58
ok i dint know stub server is rust .

dagarwal
2019-05-03 08:58
then what i need to change in the request?

matt.fellows
2019-05-03 09:01
I'm on a mobile so it's hard to see, and about to fly out of Sydney so will be afk soon. Looks like it's expecting order and orderBy query strings (and you're only sending one of them) but not sure. Find out what's the minimum request to the stub server and then work backwards from there

matt.fellows
2019-05-03 09:02
Your provider API is the problem, not the consumer

dagarwal
2019-05-03 09:03
okay will try and keep you posted

matt.fellows
2019-05-03 09:04
:+1: thanks

dagarwal
2019-05-03 09:07
thanks to you :slightly_smiling_face: but i will bother you again :stuck_out_tongue:

matt.fellows
2019-05-03 09:07
Haha I'm sure :laughing:

krzysztof.stepniak
2019-05-06 09:05
Well I tried your way but it doesn?t work for me. :confused:

asad
2019-05-07 08:55
hey anyone have idea about this error ``` FAIL tests/provider.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 2 | beforeAll(done => provider.setup().then(() => done())); 3 | > 4 | afterAll(done => provider.finalize().then(() => done())); | ^ 5 | at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.finalize (tests/config/pactTestWrapper.js:4:27) ``` i have 2 different projects consumer/provider test are working on one but on other one m getting above error

asad
2019-05-07 08:57
complete output when i run consumer/provider tests

matt.fellows
2019-05-07 09:07
Is provider being shared across the different consumer/providers? (It shouldn't)

matt.fellows
2019-05-07 09:08
I'd you share your code I can take a peek later

asad
2019-05-07 09:17
no its, and it was typical issue, somehow a node event was left kept running and was not detached, so when i tried to run again it gave , got it fixed by removing dangling node events

asad
2019-05-07 09:17
thank for reply though much appreciated :slightly_smiling_face:

asad
2019-05-07 09:31
or scratch the above comments its still there, No provider is not being shared

asad
2019-05-07 09:37
a quick question should i make different file for each consumer test of one service?

matt.fellows
2019-05-07 10:24
(Sorry I just got home an hour ago so will be intermittent with my responses)

matt.fellows
2019-05-07 10:24
I would generally have at _least_ one file per consumer/provider pair

matt.fellows
2019-05-07 10:25
I wouldn?t have multiple consumers of a provider in a single file.

matt.fellows
2019-05-07 10:25
But that is just how you organise code

matt.fellows
2019-05-07 10:28
In any case, the only thing I can think of is that you aren?t calling `provider.setup()` somewhere as that?s where that assignment is made

asad
2019-05-07 11:01
only one service is giving that issue other services are running consumer/provider tests fine.

asad
2019-05-07 11:01
i have a file named pactTestWrapper.js with following content ``` /* eslint-disable no-undef */ beforeAll(done => provider.setup().then(() => done())); afterAll(done => provider.finalize().then(() => done())); ```

asad
2019-05-07 11:02
and command m using to run provider/consumer tests is as follow ``` "test:provider": "jest --testRegex \"/*(provider.pact.js)\" --runInBand --setupFiles ./tests/config/pactSetup.js --setupTestFrameworkScriptFile=./tests/config/pactTestWrapper.js" ```

asad
2019-05-08 07:56
also when i run the consumer test even if it gives error, it still create the pact file (with changes if any)

asad
2019-05-08 09:06
also getting this error in that project `ERROR: The process "2480" not found.`

matt.fellows
2019-05-08 11:40
So if it's working for the other projects you need to find out what's different. Are you using different ports etc?

asad
2019-05-08 13:48
no configurations are same for all projects, i further debug it and found out if the project path is shorter (`C:\xampp\htdocs\afterfx-service` changed to `C:\afterfx-service`) than atleast consumer tests are working but provider tests gives an error. (file with output of console attached)

asad
2019-05-08 13:48
even thought other projects are in same directory level (`C:\xampp\htdocs\{project}`) but still working

noel.yap_slack.pact.i
2019-05-08 16:47
has joined #pact-js

asad
2019-05-10 10:28
tried solutions mentioned in this https://github.com/pact-foundation/pact-js/issues/237 Windows registry hack or moving to shallower path both did't worked :confused:

james.hattersley-dyke
2019-05-10 10:35
has joined #pact-js

james.hattersley-dyke
2019-05-10 10:41
@asad I'm having the exact same error, everything works on my local machine even when running in a Docker container. Yet CI machine dumps out the same error as yours

asad
2019-05-10 10:42
its bit more weird that with same configurations its working in other projects on local and in same directory level i have 4 different service it works in other 3 but 1 gives that error

asad
2019-05-10 10:43
tried debuging and when i moved that project with error to less shallow directory consumer tests start working but now provider test giving error < https://github.com/pact-foundation/pact-js/issues/237 > tried both solutions from that issue (window registry and moving to less shallow path still same error)

matt.fellows
2019-05-10 10:44
Is CI windows too?

matt.fellows
2019-05-10 10:44
Thanks for the debugging @asad, nicely done

james.hattersley-dyke
2019-05-10 10:45
no, linux. What's really odd is that everything works fine on Windows dev machine and a linux dev machine, also in a Docker container running on the Linux dev machine using the same imge as the CI machine

matt.fellows
2019-05-10 10:45
One possibility is that the test that is failing has something different in the contract (e.g. provider state or something). It looks like Ruby needs another file to service that request which takes the path over the limit

matt.fellows
2019-05-10 10:46
Interesting

james.hattersley-dyke
2019-05-10 10:46
I also see this ```36mPact Binary Error: /var/lib/jenkins/jobs/FE Fragment Product/branches/pact-testing/workspace@2/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.64.1/lib/ruby/bin/ruby: line 14: Fragment: command not found```

james.hattersley-dyke
2019-05-10 10:46
on CI

matt.fellows
2019-05-10 10:46
Of you can share a repro I'm happy to look. Linux should be very stable, windows is the problematic OS for reasons that should be obvious

matt.fellows
2019-05-10 10:47
Looks like a space in the path is causing issues


asad
2019-05-10 10:51
thought issue is still there :confused: will try it on linux env and see what happens

matt.fellows
2019-05-10 10:51
Thanks yep

matt.fellows
2019-05-10 10:51
Can you try removing spaces from the project path?

james.hattersley-dyke
2019-05-10 10:51
I could, but that's a jenkins workspace

james.hattersley-dyke
2019-05-10 10:53
OK renamed the project... probably gonna get lambasted by the other devs

james.hattersley-dyke
2019-05-10 11:01
that rename got me a bit further

james.hattersley-dyke
2019-05-10 11:03
wow worked!

james.hattersley-dyke
2019-05-10 11:03
Pact file was corrupted so the next build failed, the one after didn't though

james.hattersley-dyke
2019-05-10 11:04
@asad FWIW I had spaces in the file path to the ruby binary - removing those and doing a couple of rebuilds worked

asad
2019-05-10 11:11
hmm contract seems fine to me, only thing i can think is that i dont have state_handler (which is optional) so it could be cuz of that it needs extra file to handle that situation. i have attached my provider code and contract generated by consumer service.

asad
2019-05-10 11:14
@james.hattersley-dyke thank for the hint , thought given other services works on same local env i doubt there will be something wrong with anything with global settings

james.hattersley-dyke
2019-05-10 11:15
I'd just check your project paths don't contain any spaces or odd characters

asad
2019-05-10 11:27
my project is in `C:/afterfx-service` and this is the error i am getting after moving project to less shallow path ```C:/afterfx-service/node_modules/@pact-foundation/pact/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.21.0/lib/pact/provider_verifier/app.rb:3:in `require' : cannot load such file -- pact/provider_verifier/provider_states/remove_provider_states_header_middleware (LoadError) ``` still digging to solve the issue

matt.fellows
2019-05-10 11:32
ok, good to hear that worked (but not so good that spaces cause issues. I?ll raise an issue once I can repro it properly)

matt.fellows
2019-05-10 11:37
Thanks. Might be worth adding a state handler to see if that helps, but looks like the standard path length issue on Windows

matt.fellows
2019-05-10 11:38
There is an e2e example in the pact-js repository. If you can get the appveyor build to fail with the same issue, then raise an issue and we can dig into it


asad
2019-05-10 12:50
ok thank i will look into it

asad
2019-05-13 08:55
tested on linux environment with same configs and its working

asad
2019-05-13 08:55
can't seems to reproduce this issue other than that service :stuck_out_tongue:

asad
2019-05-13 08:56
will update you if i find any solid point for it to fail only in that service.

matt.fellows
2019-05-13 11:40
thanks Asad

asad
2019-05-13 13:45
np, thank to you for creating and maintaining suck a great thing :slightly_smiling_face: :+1:

phall
2019-05-13 17:20
has joined #pact-js

scott.riley111
2019-05-13 17:35
has joined #pact-js

matt.fellows
2019-05-13 21:10
You?re welcome

krzysztof.stepniak
2019-05-14 06:39
Guys, i have question. I have generated contract and after publishing it, tests are in different order than previously were on my machine. Is it intentional?

bethskurrie
2019-05-14 06:42
Yes. If you have tests that depend on the results of previous tests, you're in for a world of pain. It is actively discouraged.

bethskurrie
2019-05-14 06:43
Set up any required data in the provider state.

krzysztof.stepniak
2019-05-14 06:43
In my case it won?t help me :confused:

krzysztof.stepniak
2019-05-14 06:43
But thanks for the answer

bethskurrie
2019-05-14 06:44
Then perhaps pact is not the best tool for your scenario.

bethskurrie
2019-05-14 06:44
Gotta use the right tool for the right job :blush:

bethskurrie
2019-05-14 06:45
Would you like to explain what your problem is? Maybe someone can help you.

krzysztof.stepniak
2019-05-14 06:48
Well I think I need to setup new fresh state which include other states and it should help.

bethskurrie
2019-05-14 06:52
I usually delegate the actual set up to a nice builder object.

matt.fellows
2019-05-14 06:58
@krzysztof.stepniak people usually ask this question because the order matters to the provider. e.g. `POST /user`, and then `GET /user`

matt.fellows
2019-05-14 06:58
This is where the concept of provider states comes in

matt.fellows
2019-05-14 06:58
I say this, although I do recognise your name/avatar from previous chats - so I think you probably know this :smile:

krzysztof.stepniak
2019-05-14 06:59
:wink:

krzysztof.stepniak
2019-05-14 07:00
Ok guys, I think I?ll handle this one. Thanks once again.

matt.fellows
2019-05-14 07:01
:thumbsup:

matt.fellows
2019-05-14 07:01
you?re welcome

rjmcguinness
2019-05-14 10:59
@krzysztof.stepniak I found this in my case was due to Karma randomising order of running tests (a feature to prevent tests passing that depends on other tests running). Not sure if you?re using karma to run your pact tests, if so this might be useful https://stackoverflow.com/questions/39693307/how-to-specify-randomtrue-through-karma-jasmine (Set it to false instead of true)

krzysztof.stepniak
2019-05-14 11:00
Thanks, but I already handled it with new state. I am using mocha.

ian.mcwilliams
2019-05-14 15:48
hi @matt.fellows, i've finally gotten some time to look at this with our devops

ian.mcwilliams
2019-05-14 15:49
the codebase works fine and we can reproduce in our project codebase which is great :+1:

ian.mcwilliams
2019-05-14 15:49
trouble is, as soon as we try to use docker-compose it no longer works

ian.mcwilliams
2019-05-14 15:50
i've submitted a PR to the above project with the compose file and updated the README with the results I'm seeing, could i ask you to have a look and see if anything seems amiss please?

ian.mcwilliams
2019-05-14 15:50
@matt.fellows have sent an update to my earlier query in thread :slightly_smiling_face:

konrad.winkler
2019-05-14 19:17
has joined #pact-js

matt.fellows
2019-05-15 04:04
looking now

matt.fellows
2019-05-15 04:17
Looks just to be running slow in Docker (for me). Updating the timeout == :thumbsup:

ian.mcwilliams
2019-05-15 06:44
So simple...? :smile:

matt.fellows
2019-05-15 06:44
:man-shrugging:

ian.mcwilliams
2019-05-15 06:44
Yes, passing for me - I'll update into our project and test there

matt.fellows
2019-05-15 06:45
did it work for you?

ian.mcwilliams
2019-05-15 06:45
Sure did, will try in our project now and let you know!

ian.mcwilliams
2019-05-15 06:48
well, our devops didn't push his changes so i'll jump on him when he gets in :wink:

ian.mcwilliams
2019-05-15 06:48
will advise - thanks!

matt.fellows
2019-05-15 06:48
haha no worries :crossed_fingers:

james.hattersley-dyke
2019-05-15 09:13
Hi, I'm seeing a weird error which is causing my CI to fail - I'm using the `can-i-deploy` tool with pact-node (i think) it doesn't return a success message or often exits with exit code 2....can anyone advise? https://gist.github.com/jameshd/5a6176ce02692d7268ca7c9874dcd52f

matt.fellows
2019-05-15 09:19
can you please share the code you?re using?

james.hattersley-dyke
2019-05-15 09:20
it's v 8.3.0 of pact-node

bethskurrie
2019-05-15 09:20
James, I'd recommend find the underlying pact-broker can-i-deply executable in the node package, and calling it directly if the node is giving you problems.

james.hattersley-dyke
2019-05-15 09:27
@bethskurrie thanks, is there a ruby version you'd recommend?

bethskurrie
2019-05-15 09:28
it's baked in - you don't need ruby

bethskurrie
2019-05-15 09:28
the node can-i-deploy just wraps an underlying pact CLI (it's implemented in ruby, but the ruby is packaged with it, so you don't need to know or care about that)

bethskurrie
2019-05-15 09:29
you'll find it in one of the bin directories of the node package

james.hattersley-dyke
2019-05-15 09:29
yeah i did think that, starting to doubt myself though!

james.hattersley-dyke
2019-05-15 09:31
trying to use `find ./node_modules -name pact-broker | grep -e 'bin/pact-broker$'`

james.hattersley-dyke
2019-05-15 09:31
from CI I get: ```+ ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.64.1/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/bin/pact-broker can-i-deploy --participant fe-fragment-product --participant-version 0.4.3 --pact-broker https://sdrebuild.pact.dius.com.au --token iY8yd02Epz6MvGPARFtokA /usr/bin/env: ruby: No such file or directory```

matt.fellows
2019-05-15 09:32
are you using alpine?

james.hattersley-dyke
2019-05-15 09:32
```agent { docker { image 'node:8' } }```

bethskurrie
2019-05-15 09:33
oh, you've gone too deep

bethskurrie
2019-05-15 09:33
there should be a binary file up the top of the node package.

bethskurrie
2019-05-15 09:33
that will eventually call the line you've got there, but it has to have some things set up first in the top script.

james.hattersley-dyke
2019-05-15 09:33
`./node_modules/.bin/pact`

james.hattersley-dyke
2019-05-15 09:33
?

james.hattersley-dyke
2019-05-15 09:34
that's what I called first

bethskurrie
2019-05-15 09:34
Hm. I'd expect it to be in the standalone folder

matt.fellows
2019-05-15 09:34
It?s an open issue Beth

james.hattersley-dyke
2019-05-15 09:38
I'll just tack on a `|| true ` to the can-i-deploy for now...

bethskurrie
2019-05-15 09:38
Oh dear!

james.hattersley-dyke
2019-05-15 09:39
it's only to demo what pact can give us...

bethskurrie
2019-05-15 09:39
oh, I have a better solution

james.hattersley-dyke
2019-05-15 09:39
I gotta say you've done an awesome job with this

matt.fellows
2019-05-15 09:39
thanks James

james.hattersley-dyke
2019-05-15 09:40
the docs and support are 1st class.

matt.fellows
2019-05-15 09:40
something not right. The check you showed above looked good to me - can you show us the JS code you used to run the can-i-deploy?

bethskurrie
2019-05-15 09:40
``` docker run --rm \ -e PACT_BROKER_BASE_URL \ -e PACT_BROKER_USERNAME \ -e PACT_BROKER_PASSWORD \ pactfoundation/pact-cli:latest \ broker can-i-deploy \ --pacticipant Foo \ --latest ```

bethskurrie
2019-05-15 09:41
DOCKER ALL THE THINGS!

matt.fellows
2019-05-15 09:41
ha

james.hattersley-dyke
2019-05-15 09:41
@matt.fellows it's coming from a Jenkinsfile using the node:8 image ```sh "./node_modules/.bin/pact can-i-deploy --participant '${serviceName}' --participant-version '${serviceVersion}' --pact-broker https://sdrebuild.pact.dius.com.au --token 123456 || true"```

james.hattersley-dyke
2019-05-15 09:41
@bethskurrie i'll give that a go next :slightly_smiling_face:

bethskurrie
2019-05-15 09:42
The or true defeats the whole purpose!

bethskurrie
2019-05-15 09:42
Please try the docker!

james.hattersley-dyke
2019-05-15 09:42
i know :slightly_smiling_face:

james.hattersley-dyke
2019-05-15 09:42
ok - i'll have a go!

matt.fellows
2019-05-15 09:42
:thumbsup:

matt.fellows
2019-05-15 09:43
ahhh . Right. yeah you don?t need Pact Node for that :smile:

james.hattersley-dyke
2019-05-15 09:43
hat tip for using `--rm` no one here does that!

matt.fellows
2019-05-15 09:43
do what Beth says

bethskurrie
2019-05-15 09:43
Oh, the mess!

james.hattersley-dyke
2019-05-15 09:47
ok!

james.hattersley-dyke
2019-05-15 10:02
does this command use a accept a PACT_BROKER_TOKEN too ?

bethskurrie
2019-05-15 10:02
yes

james.hattersley-dyke
2019-05-15 10:02
sweet!

james.hattersley-dyke
2019-05-15 10:02
thanks for all your help

bethskurrie
2019-05-15 10:03
np

james.hattersley-dyke
2019-05-15 12:43
Hey Beth, I finally got the Docker command to run. I was using a Jenkinsfile and getting an error about entrypoints when running via Jenkins. Using the raw `docker run --rm ` worked

james.hattersley-dyke
2019-05-15 12:45
not sure if that's a jenkins issue or not, colleague seems to think it is


james.hattersley-dyke
2019-05-15 12:48
yeah deffo jenkins problem :slightly_smiling_face:

yousafn
2019-05-15 13:38
Hey all, I released https://github.com/YOU54F/jest-pact the other week, based on an initial proposal by @tjones, basically a simple wrapper to cut down on some of the boilerplate required work setting up a jest project with pact

matt.fellows
2019-05-15 20:52
Awesome! I'll get this referenced in the pact repo

tjones
2019-05-16 00:33
I'm excited to see this happen, @yousafn! Would have liked to be involved.

tjones
2019-05-16 00:38
but it's cool that you're taking the initiative. You can move the `test()` call inside the wrapper so that the tests read a bit cleaner (I think my current version does this).

tjones
2019-05-16 00:40
I don't think I understand the supertest bit - feels like it might be a separate wrapper?

yousafn
2019-05-16 00:48
Hey up homie :fist: , I?m up late over this side of the pond! Didn?t mean to tread on your toes, and would love for you to be involved, evolve it, do something different. After all, I am already standing on the shoulders of giants with the awesome work you guys have already done. We needed a wrapper for our services at work, as the number that wanted to consume pact was multiplying so I wanted to get something out there that we could start consuming. The supertest stuff is intertwined with our current setup at work, so it was nice to have that in there, as we won?t have to worry about setting a different port to every new provider we add in to our consuming services writing tests with the wrapper :slightly_smiling_face: Looking forward to hearing your thoughts!

yousafn
2019-05-16 00:50
ps, since late last year has been my first real foray into the world of dev / open source software, after being a tester for the past 10 years, so feedback is very much welcome and will be well received

tjones
2019-05-16 00:52
No worries at all! I probably should have released it already - I'm super pleased that someone wanted to do that :slightly_smiling_face:

tjones
2019-05-16 00:52
This is probably the kick I needed to get my thoughts on the next steps out of my head and into code

tjones
2019-05-16 00:52
I love the todo list that's at the head of the readme

tjones
2019-05-16 00:53
Seems like we're largely on the same page there. I might look at some PRs for you, if you'd like? Even if it means I have to use typescript :stuck_out_tongue_winking_eye:

tjones
2019-05-16 00:54
I think my initial reaction was a bit "aw" because I was expecting I'd release it soon - but honestly getting it out there is more valuable than my "soon"

tjones
2019-05-16 00:55
So, thanks for taking the initiative!

yousafn
2019-05-16 04:00
Sorry to steal your thunder chap, wasn?t my intention, I am just really enjoying learning about programming at the moment, lots of different languages and stacks, releasing modules, importing them in projects, is all pretty new to me, so I thought I would expand on your idea as it was useful to us, and as you said, it gives you a bit of a kick to start progressing with your thoughts into code, as I imagine there is some top knowledge stowed away in there! I am relatively new to the world of pact ( 6 months or so, same with typescript), it?s nice for people to use who are consuming your projects as they ship with types, but we can write it in pure javascript if you prefer and we can still create type definitions. I?ve added you as a contributor now :ok_hand:

bethskurrie
2019-05-16 04:09
Cross continent collaboration for the win!

ian.mcwilliams
2019-05-17 10:28
@matt.fellows just to let you know that we've now been able to integrate the kafka tests to our pipeline - thanks again for your advice!

matt.fellows
2019-05-17 10:54
Awesome! :the_horns:

matt.fellows
2019-05-17 10:54
Glad to hear

asad
2019-05-20 13:06
Hi i am bit confused regarding this example ``` // This is an example of a pact breaking // uncomment to see how it works! it.skip("Does not accept an invalid dog", () => { return messagePact .given("some state") .expectsToReceive("a request for a dog") .withContent({ name: "fido", }) .withMetadata({ "content-type": "application/json", }) .verify(dogApiHandler) }) ``` given in https://github.com/pact-foundation/pact-js/blob/master/examples/messages/consumer/message-consumer.spec.ts is it to check what consumer will do when an invalid request is given? what i am looking for and want to do is create pact/test for case when provider sends an invalid request and consumer returns an error response. Or pacts are only for success case not for failure case ?

asad
2019-05-20 13:51
*when provider sends an valid request and consumer returns an error response (cuz something went wrong on consumer side).

matt.fellows
2019-05-20 22:23
Hi Assad. It doesn?t work that way. You write the tests from the consumer?s point of view, and then the Provider must produce messages that meet those expectations - this is the ?consumer-driven? aspect. We are thinking about how to do provider-driven in this and other contexts, but are not yet ready

matt.fellows
2019-05-20 22:24
The consumer test here is about asserting that the function under test is able to handle a specific message. It?s a unit test that checks your assumptions about the interface are correct

asad
2019-05-21 06:28
hmm ok thank for help, so just to make sure the above example of `it.skip` it wont effect the pact, that is just to make sure consumer ignore/give error messages with invalid input?

matt.fellows
2019-05-21 07:21
correct, it?s just tells mocha to skip the tests

matt.fellows
2019-05-23 13:01
Hmm did I add dependabot? I recall a while ago testing some of these tools out but not applying it

yousafn
2019-05-23 13:25
Pact-js has become self aware


sankalan13
2019-05-24 06:26
has joined #pact-js

sankalan13
2019-05-24 06:36
Hey guys I am using PactWeb to generate my pact file and push to broker. I have been working on both authenticated and unauthenticated APIs from my provider. The unauthenticated APIs pacts are being verified properly on the provider verification (for which I am using the standalone ruby package). But I can't figure out how to add the Auth Header on my consumer side for the Auth API. I know that I can add it to my pact-provider-verifier by using the ```--custom-provider-header="Authorization: Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T"``` but this is the pact I am sending from my consumer side: ```beforeAll((done) => { provider.addInteraction({ state: 'workshop customer with payment option razorpay exists', uponReceiving: 'a request to GET a payment option', withRequest: { method: 'GET', path: '/springpay/api/payment-options/1/', headers: { 'Authorization' : 'Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T', 'Accept': 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json, text/plain, */*', }, body: EXPECTED_BODY, } }).then(() => { console.log('Inside 1 then'); done(); }, (err) => { console.log('Inside 1 error'); done.fail(err); }); });``` This is the error that I am getting: ```E, [2019-05-24T12:04:08.152143 #62858] ERROR -- : Diff with interaction: "a request to GET a payment option" given "workshop customer with payment option razorpay exists" Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "headers": { - "Authorization": "Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T" } } Description of differences -------------------------------------- * Could not find key "Authorization" (keys present are: X-Forwarded-Host, X-Forwarded-Proto, X-Forwarded-Port, X-Forwarded-For, Cookie, Accept-Language, Accept-Encoding, Referer, User-Agent, Accept, Connection, Host, Version) at $.headers``` Can someone please guide me to how I can send my dummy auth token to my pact file to use it to verify with the provider? I have a feeling I can use Matchers.term too but not really sure how. Please help.

vitaliy.grigoruk
2019-05-24 07:17
your consumer code should have an ability to set Authorization, so it is then passed in request headers to your provider/mockserver

vitaliy.grigoruk
2019-05-24 07:20
but it is better to relax this expectation in the contract a bit

vitaliy.grigoruk
2019-05-24 07:21
so, simply use ``` headers: { 'Authorization' : like('Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T'), 'Accept': 'application/json, text/plain, */*', }, ```

vitaliy.grigoruk
2019-05-24 07:21
where ``` const { like } = require('@pact-foundation/pact').Matchers; ```

sankalan13
2019-05-24 07:22
We use 'X-CSRFToken' for authentication and pass a cookie so I am not sure if Basic would work. I will try it once. Thanks Vitalii

sankalan13
2019-05-24 07:24
```* Could not find key "Authorization" (keys present are: X-Forwarded-Host, X-Forwarded-Proto, X-Forwarded-Port, X-Forwarded-For, Cookie, Accept-Language, Accept-Encoding, Referer, User-Agent, Accept, Connection, Host, Version) at $.headers``` Still not able to find the Authorization key here. Do I pass it on Accept instead?

vitaliy.grigoruk
2019-05-24 09:56
I think your actual consumer doesn?t send the header?

sankalan13
2019-05-24 10:21
Yeah that's exactly it. This isn't something pact is doing wrong. Will share my solution here when I find it so that others can reference it if needed. :slightly_smiling_face: Thanks Vitalii!!

diandra
2019-05-28 00:21
has joined #pact-js

sankalan13
2019-05-29 09:29
So when are you guys gonna provide a teardown feature for provider states? Currently its very hacky to delete the entire database objects every time I run my pact tests. I would be really happy to just leave my provider verifier server up and running between my pact tests. Another question I have for provider states is: Lets say I need a state where my customer exists. Now I need the customer's credentials to access an API but since I am using provider states, I am either hardcoding my values on setup (email and password) or I am creating another API to return the customer that was created on setup. Wouldn't it be awesome to have the pact provider return the data that was created so that the tester can catch it and use it inturn?

bethskurrie
2019-05-29 09:30
@sankalan13 why do you delete all the database objects each time? Can't you just clear the records?

bethskurrie
2019-05-29 09:30
The reason there is no teardown is that any teardown that relies on tearing down only the items that were supposedly created in the set up is that they will inevitably leak.

sankalan13
2019-05-29 09:31
What do you mean clear the records? I would need a fresh database every time I test.

bethskurrie
2019-05-29 09:31
It is much more reliable to clear the entire databsae before running a test, than to attempt to clear up data created within a test afterwards.

bethskurrie
2019-05-29 09:31
What sort of database are you talking about?

sankalan13
2019-05-29 09:31
I am using django with mysql so I was thinking of doing a ./manage.py flush

bethskurrie
2019-05-29 09:32
I tend to use relational databases at the moment. I have some code that truncates each table, that I call at the start of the set up.

bethskurrie
2019-05-29 09:32
I don't drop and recreate the tables each interaction. That would be very slow.

sankalan13
2019-05-29 09:33
Ahh so do you use a state mapping to call this truncate or do you do it separately before each test?

sankalan13
2019-05-29 09:33
Exactly, it'd be very slow to drop and recreate the database

bethskurrie
2019-05-29 09:33
at the start of each set up call, I clear the previous records, and then insert the new ones for this test.

sankalan13
2019-05-29 09:36
Got it. Thanks @bethskurrie :slightly_smiling_face:

sankalan13
2019-05-29 09:37
What about getting the auth data of my customer from the database once the provider state creates it? Is there an easy way to do that?

bethskurrie
2019-05-29 09:38
that's trickier. You can use Ruby middleware to intercept the request, or you can manually update the credentials of the customer to a known value during provider state set up.

bethskurrie
2019-05-29 09:38
I tend to prefer the second one.

sankalan13
2019-05-29 09:39
Yeah I think I will also go with the second one. Thank you Beth. You're super helpful :slightly_smiling_face:

bethskurrie
2019-05-29 09:40
no problem

jinal
2019-05-29 09:54
has joined #pact-js

matt.fellows
2019-05-29 10:54
@sankalan13 how are you managing provider states in the JS code? Are you using these functions (https://github.com/pact-foundation/pact-js#api-with-provider-states) or the old way with a dynamic endpoint?

matt.fellows
2019-05-29 10:55
state handlers in combination with the `requestFilter` are a good combination for this sort of thing.

sankalan13
2019-05-29 11:02
@matt.fellows out FE is in angular and our backend is in django. So we have a url: _pact/provider_states/ exposed with a POST method which calls the state mapping with different setup functions. So we are using python for the setup: ```class PactProviderSpringPayViewSet(APIView, PactMixin): permission_classes = (PactPermissions,) def post(self, request): STATES_DICT[request.data['state']]() return Response(status=HTTP_200_OK)```

sankalan13
2019-05-29 11:02
And I am using a decorator which maps the state to the specific function for setup

matt.fellows
2019-05-29 11:10
ah fair enough. Then yes, you may not have that sort of luxury yet I?m afraid.

sankalan13
2019-05-29 15:52
Haha yes. When will I have that luxury though?

shalygai.a
2019-05-29 16:05
has joined #pact-js

shalygai.a
2019-05-29 16:24
Hi! I use a https://www.npmjs.com/package/@mattersight/karma-pact-reporter to send pact file to pact broker. console displays the following error: Could not publish pact: ../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/cli/broker.rb:4:in `require' : cannot load such file -- pact_broker/client/cli/version_selector_options_parser (LoadError) from ../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/cli/broker.rb:4:in `<top (required)>' from .../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/app/pact-broker.rb:1:in `require' from ../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/app/pact-broker.rb:1:in `<main>' What can I do? :no_mouth:

yousafn
2019-05-29 18:56
Hey up, `cannot load such file -- ` are you passing a file in? possibly raise an issue on the repository, as it doesn?t look to be owned by the pact team

matt.fellows
2019-05-29 22:04
Ask / check the question on their GH issues page

sankalan13
2019-05-30 09:20
:smile: Will do sir will do

matt.fellows
2019-05-30 10:45
Thanks!

yousafn
2019-05-30 14:49
Pretty sure you just need bash installed? There?s been a few of these issues raised if you do a search

thakkarjinal29
2019-06-01 11:28
has joined #pact-js

antonello
2019-06-03 08:05
Morning everyone. I seem to recall from previous conversations (and I found a reference to it in a comment written by @bethskurrie in an issue on github) that if you decorate the whole response body with `like` matcher, that applies to all objects and properties inside the body and that you don?t need any more matchers nested in the response for specific objects. However, this does not seem to work like this in our case.

antonello
2019-06-03 08:07
``` { "body": { "pageData": [ { "type": "account", "data": {} } ], "context": { "environment": "prod" }, "canonicalUri": {redacted}/", "indexingForbidden": true, "alternateLocaleUris": [ { "locale": "de-AT", "uri": "https://{redacted}/" } ] }, "matchingRules": { "$.body": { "match": "type" } } } ```

antonello
2019-06-03 08:07
I would expect `matchingRules` to be more specific when it comes to the description of `alternateLocaleUris`

antonello
2019-06-03 08:08
Just realised I should?ve posted in #pact-node instead.

bethskurrie
2019-06-03 08:09
@antonello ita really hard to pinpoint the exact issue on slack. Can you fork the pact js project, and modify the E2E example to demonstrate your issue?

antonello
2019-06-03 08:11
I can certainly put something together, but I just wanted to make sure first that my expectation is correct.

bethskurrie
2019-06-03 08:12
Yes. If you put a like around a top level object, it carries down to all the children.

antonello
2019-06-03 08:12
and that if I do ``` const accountPage: AccountPageOutput = { pageData: [ { type: 'account', data: {}, }, ], alternateLocaleUris: [ { locale: 'de-AT', uri: '{redacted}', }, ], }; const accountPageExpectation: InteractionObject = { ... willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', Ruid: 'adedb5d9-7d9f-4110-982c-55043fc18b27', }, body: like(accountPage), }, }; ```

bethskurrie
2019-06-03 08:13
It doesn't apply an each like to the children though.

bethskurrie
2019-06-03 08:13
Sorry, I'm on a phone. I really can't read the json!

antonello
2019-06-03 08:13
Sorry, it?s too long. but the eachlike might be the problem

antonello
2019-06-03 08:14
so if there are arrays of objects, an eachLike is still needed

bethskurrie
2019-06-03 08:14
Yes

antonello
2019-06-03 08:14
:boom:

bethskurrie
2019-06-03 08:14
The like just says match by type

bethskurrie
2019-06-03 08:14
It doesn't say anything about number.

antonello
2019-06-03 08:15
but you need an eachLike even if you?re not saying anything specific about the number of objects in the array

bethskurrie
2019-06-03 08:16
Yes

antonello
2019-06-03 08:16
perfect! that explains it then!

matt.fellows
2019-06-03 08:29
no no - this is the right place!

antonello
2019-06-03 08:29
phew

matt.fellows
2019-06-03 08:29
Thanks Beth.

antonello
2019-06-03 08:30
by the way, in order to use the matchers in typescript, we?re resorting to doing ``` import { like as pactLike, eachLike as pactEachLike } from '@pact-foundation/pact/dsl/matchers'; export function like<T>(value: T): T { return pactLike(value) as unknown as T; } export function eachLike<T>(value: T): T[] { return pactEachLike(value) as unknown as T[]; } ```

antonello
2019-06-03 08:57
actually, that doesn?t work

antonello
2019-06-03 09:14
Is there any documentation or examples on how to use matchers with typescript?

matt.fellows
2019-06-03 09:45
I'm just finishing up dinner and the bed routine for the little one, will look after

antonello
2019-06-03 09:51
I haven?t managed to find any reference to it anywhere

yousafn
2019-06-03 10:18
We use matchers with ts at work without any need for additional defs. We just import like, or eachLike. I?ve never seen anyone define the as keyword in a curly braced import.

yousafn
2019-06-03 10:19
Pact-is is written in typescript now and has type defs out the box after a rewrite by Matt

antonello
2019-06-03 10:19
@yousafn

yousafn
2019-06-03 10:22
That looks like an issue in your type def for alternatelocaluri which looks to be expecting an array but it looks like your trying to pass it an object. I?m a novice dev so that?s just my initial thinking so I might be completely wrong

antonello
2019-06-03 10:23
this is what I?m battling against. If I cast (`as unknown as AlternateLocaleUri[]`), it works. But then, I cannot reuse the same body for the smoke check against the mock server.

antonello
2019-06-03 10:23
because obviously the response object is not as expected


antonello
2019-06-03 10:25
:eyes:

matt.fellows
2019-06-03 10:29
granted it?s a local reference (rather than a proper global import) because it?s run as part of the CI to ensure the release is good, but i?m fairly confident it works!

antonello
2019-06-03 10:29
thanks Matt, what what with there is an eachLike nested in the response?

matt.fellows
2019-06-03 10:29
feedback certainly welcome on the API

matt.fellows
2019-06-03 10:30
Sorry, I did?t understand that question?

antonello
2019-06-03 10:30
You can do `expect(response.data[0]).to.deep.eq(dogExample)` because the `eachLike` is around the whole response

antonello
2019-06-03 10:36
What we?re trying to do is something like ``` const kennel: Kennel = { kennelName: "my kennel", dogs: eachLike({dogName = "my dog"}) } ... body = like(kennel); ```

antonello
2019-06-03 10:38
and lets say that dogs is of type Dog[]

matt.fellows
2019-06-03 10:39
Yep...


antonello
2019-06-03 10:54
and then you get a type error on applying `eachLike` to `dogs`

matt.fellows
2019-06-03 10:57
I thought you might say that. I've thought about raising it to a typed interface but haven't yet had the time to think it thru. If you'd be so kind as to raise an enhancement request with your example we could look at it

antonello
2019-06-03 10:58
sure, will do - but what do you recommend in the meantime?

antonello
2019-06-03 11:00
doing `as unknown as Dog[]` is sufficient to work around the type issue, but the comparison between the actual and expected response fails.

antonello
2019-06-03 22:36
@matt.fellows, I have a workaround that I can post tomorrow (on my phone ready for bed now).

matt.fellows
2019-06-03 22:37
Ah, sorry I missed this (before also heading to bed)

matt.fellows
2019-06-03 22:37
I?d be keen to see what you?ve done, and more keen to see how we can make it better for you going forward

antonello
2019-06-03 22:38
Perfect, let?s catch up about this tomorrow!

antonello
2019-06-04 10:51
Hey @matt.fellows. This is how I?m thinking we can work around the problem for now. https://github.com/anto-ac/pact-js/commit/b09545b8d11c06875de494fca679ee999f767ba8

antonello
2019-06-04 10:52
However, it would be nice we could just use `kennelWithMatchers` both when setting up the interaction and when verifying it.

phall
2019-06-04 21:17
Hi everyone, I?ve been looking into moving from a provider state REST endpoint (`providerStatesSetupUrl`) to using stateHandlers. This looks like a much cleaner way of setting up the state, but I?m having some trouble. The way we currently use states is something like: ``` { state: { description: 'object exists', objectId, }, uponReceiving: `a request to fetch an object with objectId [${objectId}]`, withRequest: { method: 'GET', path: `/v1/objects/${objectId}`, }, willRespondWith: { status: 200, body: { things: eachLike({ connection: { publicIp: like('1.2.3.4') } }, { min: 1 }), }, }, } ``` Note that our state is currently an object, not a string. The provider REST endpoint receives this object and makes sure that the object exists in the database. This has been working fine. In going back through the documentation, all the examples use strings (not objects). Is our approach not recommended? Is there an alternative approach? Or am I completely missing the point?

antonello
2019-06-04 21:35
And, finally, this is an alternative approach, which is our favourite option at the moment https://github.com/anto-ac/pact-js/commit/d32add9a96c2eb935e5f0628312212156a64eb9b

rob.clarken
2019-06-04 22:47
has joined #pact-js

matt.fellows
2019-06-04 23:37
hmm technically the state is supposed to be a string. I recall somebody (it might have been you!) was doing something like this. It?s technically not designed to be used this way, but was probably more of a ?feature? bug.

matt.fellows
2019-06-04 23:37
I?ll review to see if the state handler can do something like this, but it?s certainly not portable across language implementations - so it?s not ideal.


antonello
2019-06-05 06:14
Let me know your thoughts @matt.fellows :blush:

matt.fellows
2019-06-05 06:16
Thanks Anto. It?s on my TODO for today (it?s a long list, but I?m sure I?ll at least get to read it :smile: )

vitaliy.grigoruk
2019-06-05 07:02
it was me, @matt.fellows

matt.fellows
2019-06-05 07:03
it seems there are _lots_ of clever people in this channel :stuck_out_tongue:

vitaliy.grigoruk
2019-06-05 07:03
I?m doing almost the same, passing array of js objects (using the syntax from v3 basically)

vitaliy.grigoruk
2019-06-05 07:03
however, I?m having my own proxy on provider side to handle states

vitaliy.grigoruk
2019-06-05 07:06
there is some demand for v3 in pact-js? I?m wondering if there is a roadmap of what needs to be done in order to be v3 compatible on the ?writing side?? I?ll be happy to contribute

matt.fellows
2019-06-05 08:43
I?ll put it on the list to get the roadmap published. TL;DR - we need to update the Ruby binary which is the engine under the hood. From there, we need to update any DSL with the new features

matt.fellows
2019-06-05 08:44
In the meanwhile, i?ll take a quick look at how we might be able to enable the previous naughty behaviour to avoid you needing to run proxies

phall
2019-06-05 13:11
Thanks!

phall
2019-06-05 13:12
But this is not a crazy way to be setting up states? Is there an alternative approach making sure specific IDs exist?

vitaliy.grigoruk
2019-06-05 14:04
well, the only option with spec v2 is to encode it to a string. I?m specifying state in my tests via array of objects (the value has the same format as spec v3, so it is easier to migrate to v3 in the future ``` state: [ { name: 'first state', params: { param1: 'val1', param2: 'val2' } }, { name: 'second state', params: { someParam: 'someval' } } ] ``` Then, I have a wrapper for ?addInteraction?, which does `interaction.state = JSON.stringify(originalInteraction.state)`, so it is a string. On the provider side I have my custom state handler endpoint where I deserialize `state` from string to JSON array and then I invoke state handlers based on `state.name` (passing `state.params` as args to state handler function). The logic is almost the same as what you can find inside pact-js codebase.

phall
2019-06-05 14:35
Nice approach! Thanks for sharing.

matt.fellows
2019-06-06 00:21
I certainly think there is room to add a generic typed matching interface

matt.fellows
2019-06-06 00:23
Another option, which would probably still require this under the hood anyway, would be to create decorators that could be added to typed objects. Then these objects could just be thrown around the DSL without extra functions (such as `extractPayload`)

matt.fellows
2019-06-06 00:41
e.g. a @Pact annotation that lets you specify how it maps to the contract (https://www.typescriptlang.org/docs/handbook/decorators.html)


matt.fellows
2019-06-06 00:41
I haven?t put a lot of thought into it in the TS/JS case, but it would seem a natural fit and keep the tests much cleaner and easier to understand

antonello
2019-06-06 06:37
Thanks a lot, @matt.fellows! I am not by far a typescript expert, hence I may not be the best person to even attempt this, but should I convince someone at my client to look into it before you get a chance, would you anticipate it being relatively straightforward?

matt.fellows
2019-06-06 07:16
The Decorators or your suggestion?

matt.fellows
2019-06-06 07:16
It?s a long weekend coming up here so I might get a chance :smile:

matt.fellows
2019-06-06 07:17
your suggestion is fairly straightforward, so at least as an interim, you could create a package that does it for you and after some experience/time contribute it back in.

matt.fellows
2019-06-06 07:17
As for the decorators, might be a few weeks before it?s rolled into mainstream, but perhaps possible to get an alpha release out fairly quickly

antonello
2019-06-06 09:38
Decorators are still experimental though. We?d have to specifically enable them for the pact tests.

matt.fellows
2019-06-07 03:23
Yes, true. It?s pretty common though. A lot of frameworks (e.g. Angular) use them heavily, so I don?t see them not coming in

matt.fellows
2019-06-07 03:28
But i?ll look to create a standard non-decorated interface first, and then use decorators as DSL sugar

matt.fellows
2019-06-07 03:28
this should mean we?re not tied to a path that will be unsupported later on

yousafn
2019-06-08 00:56
Hey all, hoping you can help me. I have a pact that will accept `http://localhost:8084/request/path/1` and will return ``` { "id": "1", "status": "LOOSE_MATCH" } ``` It is setup with a term matcher on the request path ``` path: term({ generate: requestPath, matcher: "/request/path/(?![2]$)\\d+" }) ``` so that it will match anything that isn?t `http://localhost:8084/request/path/2` I want to set it up so that when I perform the request `http://localhost:8084/request/path/123`, the response body will return the ID in the url that was matched ``` { "id": "123", "status": "LOOSE_MATCH" } ``` My pact test is here https://github.com/YOU54F/jest-pact-typescript/blob/requestPathExample/src/pact/client/requestPathMatching.pacttest.ts and my generated pact is here https://github.com/YOU54F/jest-pact-typescript/blob/requestPathExample/docker/pact-stub-service/pacts/test-consumer-request-path-provider.json Full example in a PR :- https://github.com/YOU54F/jest-pact-typescript/pull/101 Instructions to run example ``` 1. `git clone git@github.com:YOU54F/jest-pact-typescript.git` 2. `git checkout requestPathExample` 3. `yarn install` 4. `yarn run pact-test` 5. `cd docker/pact-stub-service` 6. `make copy-pacts` 7. `cd ../docker` 8. `docker-compose up` ```

matt.fellows
2019-06-08 11:55
Thanks @yousafn. I?ve taken a look.

matt.fellows
2019-06-08 11:55
If I understand correctly, it?s not the Pact test that is the issue - it?s using it in the stub service after? If so, this is a known limitation of the stub service at the moment

matt.fellows
2019-06-08 11:57
The stub server will respond to the matched criteria, but the actual response will be what?s specified in the example for the Pact test (in this case `1` for any request, except for the `2` case)

matt.fellows
2019-06-08 12:03
btw love what you?re doing in that repo

matt.fellows
2019-06-08 12:13
> but should I convince someone at my client to look into it before you get a chance, would you anticipate it being relatively straightforward? I may have mis read that. If your client is willing to submit a PR that would be great. I don?t imagine it being super difficult

antonello
2019-06-08 12:14
I just don?t see it happening any time soon, especially now that they have a workaround

matt.fellows
2019-06-08 12:17
ah fair enough

matt.fellows
2019-06-08 12:17
Just taking a little squiz now

matt.fellows
2019-06-08 12:17
I think you can just call `getValue()` on the matcher, rather than wrap the `extractPayload` around it

antonello
2019-06-08 12:18
But it?s annoying if you have many marchers

matt.fellows
2019-06-08 12:19
mm

antonello
2019-06-08 12:19
Most of their responses have many arrays

matt.fellows
2019-06-08 12:19
Sure.

matt.fellows
2019-06-08 12:20
Just to check that you?re not _actually_ doing this sort of test assertion: `expect(response.data[0]).to.deep.eq(dogExample)`

matt.fellows
2019-06-08 12:20
because that wouldn?t be very useful

matt.fellows
2019-06-08 12:21
I might update the TypeScript example with a more realistic scenario (where an intermediate data access layer does the API call and returns a domain model). i.e. you shouldn?t be just firing the HTTP request and asserting you got back what you expected

antonello
2019-06-08 12:25
``` function getData(state: RequestData, ruid: string = generateRuid()): Promise<PageData> { const path = '/api/v1/page/account'; const { requestHeaders } = state; const account = await httpGetJson<AccountPageOutput>(path, { ruid, requestHeaders, data: {} }); return { account }; } export const accountSpec = () => { describe('Account Page', () => { it('returns the account page data', async () => { await provider.addInteraction(accountPageExpectation); const accountPageResponse = await getData({ requestHeaders: { 'x-language-code': 'en-GB', } }, 'adedb5d9-7d9f-4110-982c-55043fc18b27'); expect(accountPageResponse).toEqual({ account: extractPayload(accountPage) }); await provider.verify(); }); }); }; ```

antonello
2019-06-08 12:26
where ``` const accountPage: AccountPageOutput = like({ pageData: eachLike( { type: 'account', data: {}, } ), context: { environment: 'prod', }, indexingForbidden: true, alternateLocaleUris: eachLike( { locale: 'de-AT', uri: '...', } ), }); ```

antonello
2019-06-08 12:27
we?re using an intermediate data access layer

antonello
2019-06-08 12:29
to setup the expected response we?re using the same type of that the domain model uses

antonello
2019-06-08 12:34
Or should we be doing something else instead?

matt.fellows
2019-06-08 12:36
no that makes sense, was just making sure. It sounds like you know what you?re doing, so that?s good!

matt.fellows
2019-06-08 12:37
Your option 2 from above certainly reads a lot better in the tests (i.e. no `extractPayload`)

matt.fellows
2019-06-08 12:37
It feels clumsy, so I can see why it would be preferable to have this in the DSL itself

antonello
2019-06-08 12:38
By the way, the `eachLike` in the snippet above is not the original one.

matt.fellows
2019-06-08 12:39
this one? ``` export function eachLike<T>(value: T): T[] { return pactEachLike(value) as unknown as T[]; } ```

antonello
2019-06-08 12:39
as I showed in the forked github example, it is: ``` import { like as pactLike, eachLike as pactEachLike } from '@pact-foundation/pact/dsl/matchers'; export function like<T>(value: T): T { return pactLike(value) as unknown as T; } export function eachLike<T>(value: T): T[] { return pactEachLike(value) as unknown as T[]; } ```

antonello
2019-06-08 12:39
yep

matt.fellows
2019-06-08 12:41
So basically, you?re having to coerce the matcher into the original type to make the tests readable/fluent, then use `extractPayload` to get the value in the assertion

antonello
2019-06-08 12:42
Exactly

matt.fellows
2019-06-08 12:42
:ok_hand:

yousafn
2019-06-08 13:07
Hey Matt, correct, the functionally I am after is in the stub service, the pact test is working spot on, however in our integration tests at work, the consumer sends an ID and and expects that ID back in the response. As we always get back ID 1, our integration tests fail. I?ve got the query param matching feature request to look at in the stub service, so I will look at both when we get some time. It?s a feature that?s available in wiremock and is really useful for upstream integration and e2e tests which I think was one of Beth?s wants for the stub service. I?ll see what we can rustle up as this and the query param matchers would really help us utilise pact throughout, and not have to revert to wiremock for some use cases. Cheers for the appreciation, the repo initially started as a way to demonstrate an issue we were having at work, without having to expose that codebase and is now growing nicely as we delve further into pact. Thanks for taking the time on a Saturday my friend!!!

matt.fellows
2019-06-08 13:11
> Thanks for taking the time on a Saturday my friend!!! Sleeping baby = Parenting = best you can get on a Saturday night :slightly_smiling_face:

matt.fellows
2019-06-08 13:11
Yes, I would love to see us do better in that space.

matt.fellows
2019-06-08 13:12
I?ve used Mountebank a lot and love the ability to use predicates. Similarly in Wiremock

matt.fellows
2019-06-08 13:14
I?ve not really had the headspace to think through how this could be done well without making the Pact DSL more complicated or confused.

matt.fellows
2019-06-08 13:17
Possibly, generators might be able to be ?upgraded? for this purpose (see https://github.com/pact-foundation/pact-specification/tree/version-3#introduce-example-generators)

matt.fellows
2019-06-08 13:18
But I think as soon as people start using it as a general DSL to do stubbing, then the contracts being produced will be overly broad. So it might need to be a separate plugin if we need to go down the multiple predicates for single interaction path.

yousafn
2019-06-08 13:29
Hahaha, I?ve not got the joy of babies yet, sleeping or otherwise! Just insomnia. I?ll have a think too mate, agree that it?s a fine line between providing additional functionality and not allowing the contracts to be too broad. I wonder if, similar to the verifier where you can override the response body, if we do a similar thing within the stub service, without having to mess with the contracts themselves. Pact spec v3 sounds like it has lots of juicy features. I might have to take pact-jvm for a spin ( as I believe it supports v3 matchers/generators ) just to have a gander at what v3 can and can?t do. I?ve also seen some tooling that can generate pacts from wiremock contracts so that?s probably worth a look in too. From memory spring-cloud-contract has some cool pact features that I did come across with some googling https://github.com/spring-cloud/spring-cloud-contract/issues/96

matt.fellows
2019-06-08 13:36
> I wonder if, similar to the verifier where you can override the response body, if we do a similar thing within the stub service, without having to mess with the contracts themselves. That?s probably the approach that would be taken, or at the very least, it would be authored separately to the test itself and appended to the conttract. Could even be a separate file that contained predicates/stub logic

matt.fellows
2019-06-08 13:36
Thanks for the link, will have to check out tomorrow, but I know Marcin did some cool stuff in that space in SCC.

matt.fellows
2019-06-08 13:37
And yes, the Atlassian team have also done some cool stuff there (although the contract conversion is all Java only :disappointed: )

matt.fellows
2019-06-08 13:37
Anywho, my wife has returned from her night out - so I better go. Feel free to keep chatting here and i?ll respond.. when I can :slightly_smiling_face:

ian.mcwilliams
2019-06-10 09:20
morning guys, i'm trying to set up the api contract tests for our project but the interactions aren't matching. we're using axios and i wonder if some of the generated parts of the request might be an issue? i've copied the headers from the actual request but the other items contains functions so not sure what to do with those, but i thought it would match on the headers alone anyway...

ian.mcwilliams
2019-06-10 09:22
and the actual request, logged by adding a request interceptor to axios:

ian.mcwilliams
2019-06-10 09:22
``` { adapter: [Function: httpAdapter], transformRequest: { '0': [Function: transformRequest] }, transformResponse: { '0': [Function: transformResponse] }, timeout: 10000, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: [Function: validateStatus], headers: { common: { Accept: 'application/json, text/plain, */*' }, delete: {}, get: {}, head: {}, post: { 'Content-Type': 'application/x-www-form-urlencoded' }, put: { 'Content-Type': 'application/x-www-form-urlencoded' }, patch: { 'Content-Type': 'application/x-www-form-urlencoded' }, Authorization: 'apiKey ' }, method: 'get', baseURL: 'https://valid.url.base.co.uk', proxy: false, url: '/api/v2/products/sub-categories/user/abc' } ```

bethskurrie
2019-06-10 09:23
Those headers are weird

bethskurrie
2019-06-10 09:23
It looks like it's sent through the axios header configuration, not the actual values.

bethskurrie
2019-06-10 09:24
Or rather, you've set up an expectation with a configuration object.

ian.mcwilliams
2019-06-10 09:24
i see what you mean, it probably uses common and adds whatever is specified for the request type, so nothing for this get

bethskurrie
2019-06-10 09:25
Settting up the expected request is code you control though, not axios.

ian.mcwilliams
2019-06-10 09:26
i've changed the specified interaction to:

ian.mcwilliams
2019-06-10 09:26
``` "headers": { "Accept": "application/json, text/plain, */*", "Authorization": "apiKey " }```

ian.mcwilliams
2019-06-10 09:26
everything else the same - mockserver log still shows no match though

bethskurrie
2019-06-10 09:27
What's it not matching on?

bethskurrie
2019-06-10 09:29
OK, when you see that pattern of logs, it usually means your tests is executing on the wrong order.

bethskurrie
2019-06-10 09:30
From those logs, no actual request came through at all.

ian.mcwilliams
2019-06-10 09:30
i've got one test running:

ian.mcwilliams
2019-06-10 09:30
```const { targetFunction } = require('../../.....'); const { Matchers } = require('@pact-foundation/pact'); const { term } = Matchers; const guid = 'abc'; describe('something', () => { it('does something', done => { provider.addInteraction({ uponReceiving: 'some request', withRequest: { method: 'GET', path: '/api/v2/products/sub-categories/user/abc', headers: { Accept: 'application/json, text/plain, */*', Authorization: 'apiKey ' } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: { status: 200 } } }); targetFunction(guid) .then(response => { console.log(response); // expect(response).toEqual({ status: 202 }); }) .then(done) // .catch(err => { // console.log('THISERR', err, 'ERREND') // }); }); }); ```

bethskurrie
2019-06-10 09:31
Now, you'll need an actual JavaScript developer to help you.

bethskurrie
2019-06-10 09:32
It'll be something to do with the order of execution and the way your callbacks or promises are set up.

bethskurrie
2019-06-10 09:32
I'm no js expert in afraid. Matt or Michel should be able to advise.

ian.mcwilliams
2019-06-10 09:34
cool - thanks for your help! i'll see if i can play about with a few things with that in mind, in the meantime :slightly_smiling_face:

matt.fellows
2019-06-10 09:52
addInteraction is a promise, you'll need to wait for that to complete before calling targetFunction

matt.fellows
2019-06-10 09:52
I'm just finishing tea so on a mobile, but that could be the cause of the interactions coming in out of order.

matt.fellows
2019-06-10 09:54
Ah those logs don't seem to indicate that a verification is happening before the interaction is registered

ian.mcwilliams
2019-06-10 10:29
i added an await just to try, no change in outcome

bethskurrie
2019-06-10 10:33
All requests to the mock service are logged.

bethskurrie
2019-06-10 10:34
So, if you don't see any request logged between registering the interaction, and verifying, it's because there were no actual requests made to the mock service.

bethskurrie
2019-06-10 10:34
So either your timing is out, your request is being made to the wrong address, or it just isn't being made at all.

matt.fellows
2019-06-10 12:46
@ian.mcwilliams you mentioned in your actual request that axios logged that the base url was `'https://valid.url.base.co.uk` - is that just a placeholder, or is it actually hitting an external URL? Just confirming that it has actually been configured to point to the mock server provided by Pact?

ian.mcwilliams
2019-06-10 14:21
it's not hitting localhost:port - and that would appear to be the issue, because although jest runs the test config (and is doing so) by default, at the point that the axios.create call is made the default config for the host value is being used

ian.mcwilliams
2019-06-10 14:21
i'll sort something out to get the test host value picked up and see if that takes care of it

matt.fellows
2019-06-10 21:27
:+1:

matt.fellows
2019-06-10 21:28
Sounds like that'd be it

sgleadow
2019-06-10 23:09
@sgleadow has left the channel

ian.mcwilliams
2019-06-13 09:57
@matt.fellows @bethskurrie have completed this after being away for a couple of days - yes the issue above was required, it also needed the config to specify the port as part of the url, because axios doesn't allow you to set the port separately and if you don't add it to the baseUrl then it will default to 80 - so config was `{ url: localhost:8989, port: 8989 }`

ian.mcwilliams
2019-06-13 09:57
then i just copied the missing headers from the actual call (still logged with an axios interceptor) into the pact interaction, and we have a passing test :slightly_smiling_face:

ian.mcwilliams
2019-06-13 09:58
thanks again for your help!

bethskurrie
2019-06-13 09:58
Glad you worked it out!

matt.fellows
2019-06-13 11:24
you?re welcome, and thanks for circling back!

vitaliy.grigoruk
2019-06-14 09:05
Hi everybody. I have a question about matchers when doing provider verification. In mockserver interaction definition I have the following response body (matching by type): ``` "diff": { "value": decimal(0) } ``` However, actual provider may also return `"value": 0.1`, which is also a valid result. The issue is when I run provider verification, it fails: ``` "diff": { - "value": Fixnum + "value": Float } ``` How should I define a matcher to allow both `0` and float numbers?

matt.fellows
2019-06-14 09:15
Ah, this is tough case. I think there is an outstanding issue somewhere that covers it. At the moment that's not possible across languages in a portable way I'm afraid

vitaliy.grigoruk
2019-06-14 09:58
I guess we need a `number` matcher in JS, which matches both integers and floats

matt.fellows
2019-06-14 10:12
The example should be an actual decimal (instead of zero, because js will lose that resolution)

matt.fellows
2019-06-14 10:12
But yes, that would be one way out of it

matt.fellows
2019-06-14 10:12
I think a decimal matcher should include an integers, but not the other way arouns

matt.fellows
2019-06-14 10:13
This would need fixing in the Ruby code. I'll see if I can chase up a bit later when back on PC

vitaliy.grigoruk
2019-06-14 10:53
> I think a decimal matcher should include an integers, but not the other way around That?s what I thought as well.

matt.fellows
2019-06-14 11:56
Is your provider also JS?

matt.fellows
2019-06-14 11:56
(also sorry for poor spelling, was on my mobile before)


vitaliy.grigoruk
2019-06-14 12:13
yes, both are in JS

matt.fellows
2019-06-14 12:46
thx

vitaliy.grigoruk
2019-06-14 12:49
I?ve commented on that ticket? not sure what to about it.

vitaliy.grigoruk
2019-06-14 13:02
wow, that was quick @matt.fellows!

matt.fellows
2019-06-14 23:05
No worries. I have an idea as to have I can support it in Pact JS fairly quickly. Need to chat with maintainers on portability

mui_ume
2019-06-17 11:34
has joined #pact-js

mui_ume
2019-06-17 11:44
Hi I like to know how to add pact test to a react-native app project. however this react-active app has it's jest test written inside it's library module. since I am writing pact test, I guess I won't be adding pact to the internal library module but do it outside where index.js resides?

mui_ume
2019-06-17 11:44
index.js code snippet: ```import { AppRegistry } from 'react-native'; import App from './App/index'; import { name as appName } from './app.json'; AppRegistry.registerComponent(appName, () => App);```

matt.fellows
2019-06-17 11:57
Your pact tests should focus on the collaborator (sometimes referred to as service delegates) that is responsible for communicating to external systems / APIs.

matt.fellows
2019-06-17 11:59
It should be pure JS that you?re testing. I?m not a react expert, but I?d say it?s unlikely that you?be testing the `index.js` file directly

matt.fellows
2019-06-17 12:00
If there is a dependency on react in the bit you?re testing, that would seem to me to be the wrong place

abubics
2019-06-18 00:55
@mui_ume Ideally, on the consumer side, you'd have an API client as its own js module, with the single responsibility of talking to an API and handling its various responses. As plain js, it should be framework independent, and relatively platform independent (with possible exceptions for `fetch`/`axios`/whatever). The Pact tests are then written as unit tests in the context of that API client, and can be run without a browser, or react, or any other heavy dependencies.

matt.fellows
2019-06-18 06:05
@vitaliy.grigoruk if you haven?t seen already, this should now be fixed in the latest Pact JS (and soon all languages that use Ruby under the hood)

ian.mcwilliams
2019-06-18 10:31
hi guys - i've got working api tests locally which fail when i run them in a container when the test attempts to call addInteraction on the provider, with the message that it cannot call addInteraction on undefined. i can log the provider (Pact) object in the previous line, i've even logged the properties of the object and they include the addInteraction method. is this something you've experienced before?

matt.fellows
2019-06-18 10:33
No haven't seen it

matt.fellows
2019-06-18 10:34
But it works outside of docker? So this probably means the container environment is insufficient somehow or incorrectly configured. Are you using Alpine and have you read up on the related Alpine setup issues?

ian.mcwilliams
2019-06-18 10:44
we'd previously had some issues with ruby in alpine and we're using the setup you recommended at that time:

ian.mcwilliams
2019-06-18 10:44
```FROM node:10-alpine RUN apk add --no-cache --virtual build-dependencies build-base git RUN apk --no-cache add ca-certificates wget bash \ && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \ && apk add glibc-2.29-r0.apk```

ian.mcwilliams
2019-06-18 10:46
yeah works outside the container - i've spent some time with our devops lead this morning and he hasn't been able to identify anything that should cause an issue

matt.fellows
2019-06-18 10:47
cool, thanks Ian.

dalsidhu99
2019-06-18 10:57
has joined #pact-js

mui_ume
2019-06-18 13:04
@abubics, I have been looking at your github repository. I still could not figure out how to add pact test to my react native app which is the frontend and making HTTP requests call to the backend. my react native has this project structure App-> Screens-> Login which has an index.js, LoginHelper.js, and this LoginHelper.js has this code snippet: const loginEndpoint = settings.getLoginEndpoint(); try { const resp = await http://api.post(loginEndpoint, reqData); where it make a post request to the endpoint and get response. ..... this is where I want to use pact to do the contract testing..

mui_ume
2019-06-18 13:06
I create a folder pact and try to add setup.js, jest-wrapper.js, publish.js, in VS, it is show as Red, not sure if I inserted at the right place though?

mui_ume
2019-06-18 13:06
it seem not so straightforward to setup pact ?

mui_ume
2019-06-18 13:15
Sorry I?m totally new to pact contract testing and need to integrate into the developer source code is a challenge I don?t seem to see how to integrate Given the example are not so relevant

mui_ume
2019-06-18 13:17
I have been using postman for API testing and I find it more straightforward than pact Which is not so clear how to setup for my project

ian.mcwilliams
2019-06-18 13:40
@matt.fellows i can add that if any item is missing that is required it gives an error message, eg if i run with:

ian.mcwilliams
2019-06-18 13:40
```provider.addInteraction({ uponReceiving: 'some request', withRequest: { method: 'GET' }, willRespondWith: { status: 200 } }); });```

ian.mcwilliams
2019-06-18 13:41
i get:

ian.mcwilliams
2019-06-18 13:41
``` You must provide a path. 10 | describe('something', () => { 11 | it('does something', async () => { > 12 | provider.addInteraction({ | ^ 13 | uponReceiving: 'some request', 14 | withRequest: { 15 | method: 'GET' ```

ian.mcwilliams
2019-06-18 13:41
if i then add a path then it's back to:

ian.mcwilliams
2019-06-18 13:41
``` TypeError: Cannot read property 'addInteraction' of undefined 10 | describe('something', () => { 11 | it('does something', async () => { > 12 | provider.addInteraction({ | ^ ```

vitaliy.grigoruk
2019-06-18 20:38
That?s great! Thank you, @matt.fellows! Will try it tomorrow

matt.fellows
2019-06-18 21:10
Hi Lay. Forgetting Pact for a moment, it?s not a tool like Postman that can be run from ?the outside? so to speak. You need to be able to write a unit test within the code base. Might I suggest you start by writing a simple Jest unit test in your code (without Pact). Once you can test your LoginHelper with Jest, you could look to introduce Pact. There really is nothing React Native specific you need to do to make Pact work for you. It is just a unit testing tool

matt.fellows
2019-06-18 21:11
Looks like you?re in the right place - we want to be testing the function that does this work.

matt.fellows
2019-06-18 21:12
Can you write a standard Jest (or whatever unit testing framework) test for this?

matt.fellows
2019-06-18 21:12
Once you?ve done that, adding Pact should be trivial.

matt.fellows
2019-06-18 21:17
That?s strange, I can?t understand how this might happen as `provider` is a variable under your control. Could something else be modifying it? How is `provider` being configured?

matt.fellows
2019-06-18 21:17
If you could whip up a little code for me to repro, I?d happily take a look

abubics
2019-06-18 23:30
btw @mui_ume, which github repo were you looking at? I don't remember linking you to any . . .

tjones
2019-06-19 02:49
@ian.mcwilliams I don't believe that `port` is a key in axios config - so you should be able to do `{ url: 'localhost:8989'} `

tjones
2019-06-19 02:51
Also, you can get it from pact js, too - for example: ``` beforeEach(() => { yourConfig.api.baseUrl = provider.mockService.baseUrl; }); ```

tjones
2019-06-19 02:51
this is nicer because it means you don't need to know what port it is running on (and you can run multiple mock servers if your tests are running concurrently)

tjones
2019-06-19 02:53
If you're using Jest, @yousafn and I have been working on a wrapper to make this whole process a bit nicer: https://github.com/YOU54F/jest-pact/#readme

tjones
2019-06-19 02:54
``` import { pactWith } from 'jest-pact'; import { Matchers } from '@pact-foundation/pact'; import api from 'yourCode'; pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, provider => { let client; beforeEach(() => { client = api(provider.mockService.baseUrl) }); describe('health endpoint', () => { // Here we set up the interaction that the Pact // mock provider will expect. // // jest-pact takes care of validating and tearing // down the provider for you. beforeEach(() => provider.addInteraction({ state: "Server is healthy", uponReceiving: 'A request for API health', willRespondWith: { status: 200, body: { status: Matchers.like('up'), }, }, withRequest: { method: 'GET', path: '/health', }, }) ); // You also test that the API returns the correct // response to the data layer. // // Although Pact will ensure that the provider // returned the expected object, you need to test that // your code recieves the right object. // // This is often the same as the object that was // in the network response, but (as illustrated // here) not always. it('returns server health', () => client.health().then(health => { expect(health).toEqual('up'); })); }); ```

tjones
2019-06-19 02:55
We really need a blog post about this

tjones
2019-06-19 02:57
@mui_ume Here is a react project with Pact tests in it (it's not react native, but the pattern should be similar): https://github.com/TimothyJones/PlusOne/blob/master/src/Game/Board/service/api/api.pact.test.js

tjones
2019-06-19 02:57
In this case, we have a service module that contains the API


matt.fellows
2019-06-19 02:59
Awesome - thanks Tim!

matt.fellows
2019-06-19 02:59
Perhaps we should add a link to this project from GitHub for others?

tjones
2019-06-19 03:00
Note that this is completely separated from React - all the calling code needs to know is the domain model (in this case, that there is a score board that the app can tell that the player reached a particular score). The caller doesn't know anything about the network requests (post/get etc).

tjones
2019-06-19 03:00
I think we should just clean up the examples :slightly_smiling_face:

tjones
2019-06-19 03:00
Probably a React example

tjones
2019-06-19 03:00
could be added

tjones
2019-06-19 03:04
Note that the Pact test linked above wraps the whole API module - ie, it tests what your code will call when you want to do actions through the API. This is important because it means that the pact test doesn't read like this:: ``` // axios.get(`${apiBase}/something`).then( () => {/* validate response */} ) ``` instead, it reads like this: ``` // This is much more valuable because it's testing the code your app will definitely be calling yourApi.getSomething().then( () => {/* validate response */} ) ```

ian.mcwilliams
2019-06-19 09:16
@tjones that's correct as per my findings, no port specifically for axios so pass as part of the host string

ian.mcwilliams
2019-06-19 09:17
the other stuff you mention sounds like it could be very good, but at the moment i have to make the test run in a container before i can start to scale, and port conflict potentially become an issue!

tjones
2019-06-19 11:00
Very reasonable

ian.mcwilliams
2019-06-19 12:57
@matt.fellows it was the timeout, increased it and the tests passed in the container :joy:

mui_ume
2019-06-20 05:45
thanks Tim Jones

mui_ume
2019-06-20 08:38
Hi Tim, do you need to setup the pact mock provider?

mui_ume
2019-06-20 08:46
I am trying to follow this step here https://reflectoring.io/pact-react-consumer/

mui_ume
2019-06-20 08:49
the steps here is well explained but I need to fit into my project in my case, it's to call the login endpoint which is in my project structure located at App/Screens/Login/LoginHelper.js

mui_ume
2019-06-20 08:49
I put my pact folder at the root directory, same level as App

mui_ume
2019-06-20 08:50
it will be good to have a simpler example to follow. I need to figure and replace the Scoreboard etc with my own project use case


mui_ume
2019-06-20 09:13
I clone the above and try to run npm i and npm t

mui_ume
2019-06-20 09:14
got some FAILED message

mui_ume
2019-06-20 09:14
```20 06 2019 17:13:06.788:INFO [pact]: Pact Mock Server running on port: 1234 20 06 2019 17:13:06.822:WARN [watcher]: Pattern "/Users/tohlaymui/Desktop/pact-js-master/dist-web/pact-web.js" does not match any file. 20 06 2019 17:13:06.830:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/ 20 06 2019 17:13:06.831:INFO [launcher]: Launching browsers PhantomJS_without_security with concurrency unlimited 20 06 2019 17:13:06.834:INFO [launcher]: Starting browser PhantomJS 20 06 2019 17:13:07.894:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket t6nvJHPDCQQhpbhrAAAA with id 50322375 PhantomJS 2.1.1 (Mac OS X 0.0.0) Client sayHello says hello FAILED ReferenceError: Can't find variable: Pact in client-spec.js (line 8) client-spec.js:8:26 loaded@http://localhost:9876/context.js:168:19 TypeError: undefined is not an object (evaluating 'provider .addInteraction') in client-spec.js (line 25) client-spec.js:25:17 loaded@http://localhost:9876/context.js:168:19 ReferenceError: Can't find variable: Promise in client.js (line 18) sayHello@client.js:18:19 client-spec.js:47:24 loaded@http://localhost:9876/context.js:168:19 PhantomJS 2.1.1 (Mac OS X 0.0.0) Client findFriendsByAgeAndChildren returns some friends FAILED```

mui_ume
2019-06-20 09:16
I got a question: where should I place my pact folder? in the root directory or at the place where I want to do the test,in my case App/Screens/Login?

mui_ume
2019-06-20 09:16
my Login folder has index.js, LoginHelper.js, styles.js

mui_ume
2019-06-20 09:17
loginHelper.js has this code snippet: ```const loginEndpoint = settings.getLoginEndpoint(); try { const resp = await http://api.post(loginEndpoint, reqData); if (resp.ok) { const loginRespBody = await resp.json(); const { authToken, clientInfo } = loginRespBody; if (authToken) { const sessionResp = await api.startSession({ clientId: clientInfo.clientId, user: { authToken, userId: data.user.userId, }, });```

mui_ume
2019-06-20 09:17
this is where I want to test the endpoint

mui_ume
2019-06-20 10:01
let me share my folder....

matt.fellows
2019-06-20 10:42
You'll probably need to do an npm install in the root directory also

matt.fellows
2019-06-20 10:55
@mui_ume that example is not a Jest example, it is one of the Karma examples. Did you mean that?


mui_ume
2019-06-20 10:56
Is it not jest ?

mui_ume
2019-06-20 10:57
I?m going to continue working on later in an hour time ...

matt.fellows
2019-06-20 10:57
no worries

matt.fellows
2019-06-20 10:58
yes that?s definitely a jest example, the output you shared however is not consistent with that test. It looks like one of the Karma examples (`findFriendsByAgeAndChildren` is only something that exists in the karma examples)

matt.fellows
2019-06-20 11:04
I?ll have a go at making the examples easier to run. I can see why it might be difficult coming to a complex ecosystem like TS/JS

mui_ume
2019-06-20 12:54
I created a pact folder at the root same level as App

mui_ume
2019-06-20 12:54
in my pact folder, I added pactSetup.js with the content: // ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.port = 8080; global.provider = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'MyConsumer', provider: 'MyProvider', host: '127.0.0.1', });

mui_ume
2019-06-20 12:55
pactTestWrapper.js with the content: global.beforeAll((done) => { global.provider.setup().then(() => done()); }); global.afterAll((done) => { global.provider.finalize().then(() => done()); });

mui_ume
2019-06-20 12:55
publish.js with the content: onst { publisher } = require('@pact-foundation/pact-node'); const { path } = require('path'); const opts = { providerBaseUrl: 'http://localhost:8080', pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], pactBroker: 'https://localhost:3000', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, consumerVersion: '2.0.0', }; publisher.publishPacts(opts).then(() => global.done());

mui_ume
2019-06-20 12:55
in my package.json, I have these in: "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "lint": "eslint App/", "react-devtools": "react-devtools", "test": "jest", "test:pact": "cross-env CI=true react-scripts test --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch \"**/*.test.pact.js\"", "publish:pact": "node ./pact/publish.js" },

mui_ume
2019-06-20 12:56
"devDependencies": { "@babel/runtime": "^7.1.2", "@pact-foundation/pact": "^8.2.6", "@pact-foundation/pact-node": "^8.6.0", "axios": "^0.19.0", "babel-eslint": "^7.1.1", "babel-jest": "23.6.0", "babel-plugin-transform-remove-console": "^6.9.4", "babel-preset-react-native": "^4.0.1", "cross-env": "^5.2.0",

mui_ume
2019-06-20 12:56
"jest": { "preset": "react-native", "testEnvironment": "node" }

mui_ume
2019-06-20 12:57
from this link https://reflectoring.io/pact-react-consumer/, I run npm run test:pact

mui_ume
2019-06-20 12:57
it give me some errors: > cross-env CI=true react-scripts test --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch "**/*.test.pact.js" events.js:174 throw er; // Unhandled 'error' event ^ Error: spawn react-scripts ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19) at onErrorNT (internal/child_process.js:415:16) at process._tickCallback (internal/process/next_tick.js:63:19) at Function.Module.runMain (internal/modules/cjs/loader.js:745:11) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3) Emitted 'error' event at: at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)

mui_ume
2019-06-20 12:58
I am not sure what to do next? did I miss out any step here?

mui_ume
2019-06-20 12:59
I just want to make sure my pact configuration is ok before I continue to Let?s implement a REST client for which we?ll later create a consumer-driven contract.....

mui_ume
2019-06-20 12:59
but the step 'npm run test:pact' didn't work for me

matt.fellows
2019-06-20 13:02
Might I suggest you publish this to Github so that anyone who wants to help you can run the same code you?re running? This will make debugging much easier

mui_ume
2019-06-20 13:02
let me try to extract out the key parts...

matt.fellows
2019-06-20 13:02
Also, I?ve made a quick start on making the exampples in pact-js standalone (so that you can just run a `npm it` and it should just work). See this branch https://github.com/pact-foundation/pact-js/tree/feat%2Fexamples-use-exported-packages

matt.fellows
2019-06-20 13:04
no worries

matt.fellows
2019-06-20 13:04
Are you running the tests from this project in that article: https://github.com/thombergs/code-examples/tree/master/pact/pact-react-consumer

matt.fellows
2019-06-20 13:04
or are you writing your own now?

matt.fellows
2019-06-20 13:05
or rather, did you first get the tests all running successfully in that project before trying it for yourself?


matt.fellows
2019-06-20 13:06
And lastly, have you written a basic jest unit test? My worry is that you?re learning too many things at once: Unit testing in React, Jest and then Pact itself. You need to be comfortable in the first two before trying Pact.

matt.fellows
2019-06-20 13:06
It?s in the article you shared (the one Tom H wrote

mui_ume
2019-06-20 13:06
I was just looking at the blog and try to follow

matt.fellows
2019-06-20 13:06
OK, I?d suggest studying and running his code first. But not until you first understand Jest and unit testing in React

matt.fellows
2019-06-20 13:06
I have to run now (it?s late) but good luck!

mui_ume
2019-06-20 13:07
sure thanks for the tips.

matt.fellows
2019-06-20 13:07
As mentioned, I fixed the jest tests in this branch https://github.com/pact-foundation/pact-js/tree/feat/examples-use-exported-packages/examples/jest. You should be able to run this without building pact itself

mui_ume
2019-06-20 13:08
I just run your example/jest, it works now

mui_ume
2019-06-20 13:08
I will look at this example and work from there.... thanks a bunch!

closenet.uk
2019-06-20 14:46
has joined #pact-js

closenet.uk
2019-06-20 14:55
Hi #pact-js, I have a question regarding the term matcher using regex, why it doesn't like the below regex format, although it's a ruby version and tried on the ruby regex tester? it's even mentioned as an example in PACT docs! "update_date": term({ generate: '02/11/2013', matcher: '\d{2}\/\d{2}\/\d{4}' })

closenet.uk
2019-06-20 14:56
found why it's not liking the above regex format, for the benefit of others, all we need to is to add another backslash in front of the actual \d backslash *\\d{2}\/\\d{2}\/\\d{4}*



viktor
2019-06-21 11:53
has joined #pact-js

viktor
2019-06-21 13:56
Hello, so i have an endpoint that i want to match that returns exactly 3 different elements in an array. how can i test that: a) they are exactly 3 b) that they are all different, if i do: ``` eachLike( term({ matcher: 'A|B|C', generate: 'C' }), { min: 3 } ) ``` the elements can be more than 3, and they can also be the same 3 times. I also tried ``` like([ term({ matcher: 'A|B|C', generate: 'A' }), term({ matcher: 'A|B|C', generate: 'B' }), term({ matcher: 'A|B|C', generate: 'C' }) ]) ``` and while that stubs my three different elements, they dont validate that they are different. Is there a way to achieve this? or im i looking at this wrong?

matt.fellows
2019-06-22 02:38
In pact js you can't specify the specific array length with an eachLike matcher

matt.fellows
2019-06-22 02:39
Just remove the eachLike wrapper and have an array that contains three elements. If the values must be different and there are only 3 possible vakues, then just specify the exact array you're expecting (i.e. don't use matchers)

dalsidhu99
2019-06-23 11:33
hi all, i was wondering if somebody could please help. I am new to pact and still a beginner with javascript but i have managed to get a test/interaction working against the mock client. However sometimes the test passes and sometimes it doesnt

dalsidhu99
2019-06-23 11:34
see the mock-server integration log here

dalsidhu99
2019-06-23 11:35
it looks like there is some time taken to actually get the response back from the server and in that time pact is already checking to see whether there has been a response that has come back

bethskurrie
2019-06-23 11:35
Looks like you've got timing issues. Sometimes your test is executing before your interactions have been set up, and sometimes it's ok.

matt.fellows
2019-06-23 11:35
Hi @dalsidhu99 it looks like requests are coming in out of order. So I suspect you aren't handling a promise correctly

dalsidhu99
2019-06-23 11:36
i have added a few asyncs and awaits but this doesnt seem to be resolving the issue

matt.fellows
2019-06-23 11:36
Show us your code and I can take a quick look

dalsidhu99
2019-06-23 11:36
(im a newbie to js)

dalsidhu99
2019-06-23 11:36
thank you

dalsidhu99
2019-06-23 11:36
describe('Consumer test example', () => { beforeEach(async () => { await service.setup() }) it('can return a response', async () => { l('add interaction') await service.addInteraction(interactions.getFirstUser); await client.getProducts() await service.verify() await service.finalize() }) })

dalsidhu99
2019-06-23 11:37
******

dalsidhu99
2019-06-23 11:37
async function getProducts () { await request.get({url: USERS_URL}, function (error, response, body) { expect(response.statusCode).to.equal(200); expect(response.body).to.contains("Dal"); }) return getProducts }

dalsidhu99
2019-06-23 11:37
(apologies for not using code snippet)

bethskurrie
2019-06-23 11:39
And this is the part where I go to bed and leave Matt to help you because I'm so not a javascript person :-P

matt.fellows
2019-06-23 11:42
Something looks wrong in getproducts. That's not a promise but a callback so by putting async and await on that won't do anything.

matt.fellows
2019-06-23 11:42
I'd look to that method as the source of the issue (or look at a promise lib like axios)

dalsidhu99
2019-06-23 11:43
thanks matt, I have heard about axios so will def give that a look!

dalsidhu99
2019-06-23 23:13
and how would we publish a test to the pact broker? i have just set up the web based view, .. http://pact.dius.com ..



matt.fellows
2019-06-23 23:21
You probably also want to read how to tag properly at https://github.com/pact-foundation/pact_broker/wiki/Using-tags

dalsidhu99
2019-06-24 00:13
and as for pactbroker username/password, i only have the UI credentials through email and api token

matt.fellows
2019-06-24 00:16
There is a mode for authenticating with a bearer token

dalsidhu99
2019-06-24 00:32
does/will the UI at some point allow us to view the interactions that have been ran against a service?

matt.fellows
2019-06-24 00:39
What does that mean, sorry?

mui_ume
2019-06-24 03:27
Hi, When I add "@pact-foundation/pact": "^8.2.6", "@pact-foundation/pact-node": "^8.6.0", "axios": "^0.19.0", to the package.json, I will got a error when building the react-native app in xcode. this is the error I got : error: bundling failed: TypeError: Cannot read property 'bindings' of null at Scope.moveBindingTo (/Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@babel/traverse/lib/scope/index.js:864:13) at BlockScoping.updateScopeInfo (

mui_ume
2019-06-24 03:27
any one encounter such error?

mui_ume
2019-06-24 03:33
suspect babel pact has some problem with transpiling is it has any specific version that it need for babel

mui_ume
2019-06-24 04:17
I got to remove the "react-native" from the preset at babelrc in order to build the app in xcode. now the babelrc looks like this: "presets": ["module:metro-react-native-babel-preset"],

mui_ume
2019-06-24 04:22
but when I run npm run test:pact, it will give an error ```npm run test:pact > tlstellaclientapp@0.0.1 test:pact /Users/tohlaymui/Desktop/tl_stella-client_app > jest __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch "**/*.test.pact.js" FAIL App/Screens/Login/__tests__/login.service.test.pact.js ? Test suite failed to run Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/Users/tohlaymui/Desktop/tl_stella-client_app" at node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19 at Array.map (<anonymous>) at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20) ```


mui_ume
2019-06-24 04:28
this fixed the issue

mui_ume
2019-06-24 04:29
I added this line to package.json ```"jest": { "preset": "react-native", "testEnvironment": "node", "transform": { "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js" } }```

tjones
2019-06-24 04:31
Thanks @mui_ume. It looks like the issue you're experiencing is unrelated to pact?

mui_ume
2019-06-24 04:34
yes but if you are using react-native app with babelrc, and then run the pact test, it will have this issue Couldn't find preset 'module: metro-react-native-babel-preset'...

tjones
2019-06-24 04:47
Unless I'm missing something, isn't this a problem with react-native and Jest, rather than react-native and pact?

tjones
2019-06-24 04:47
(yes, you'll hit it if you're using Jest as your test runner for react-native, but that's true for all your Jest tests, not just pact)

tjones
2019-06-24 04:54
Apologies if I missed something

matt.fellows
2019-06-24 05:02
Yep, I think this is true. Lay has taken on the burden of learning JS, React, React Native, Jest and Pact all in one go - so rather impressive to get a green Pact consumer build in one weekend :stuck_out_tongue:

dalsidhu99
2019-06-24 09:30
Apologies, i had just got the pact published to the broker, wanted to see if the consumer mock tests against the provider could be seen via the ui (not sure if it would make sense if we did, just thinking out aloud)

mui_ume
2019-06-25 03:03
Hi, when I run npm run publish:pact, I got this error > node ./pact/publish.js /Users/tohlaymui/Desktop/tl_stella-client_app/pact/publish.js:6 pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], ^ TypeError: Cannot read property 'resolve' of undefined at Object.<anonymous> (/Users/tohlaymui/Desktop/tl_stella-client_app/pact/publish.js:6:26)

mui_ume
2019-06-25 03:03
my pact/publisher.js: ```const { publisher } = require('@pact-foundation/pact-node'); const { path } = require('path'); const opts = { providerBaseUrl: 'http://localhost:8080', pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], pactBroker: 'https://tl.pact.dius.com.au/', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, consumerVersion: '2.0.0', }; publisher.publishPacts(opts).then(() => console.log('Pacts successfully published')); ```

mui_ume
2019-06-25 03:03
node --version v10.15.1

abubics
2019-06-25 03:44
this bit: ``` pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], ^ TypeError: Cannot read property 'resolve' of undefined ```

abubics
2019-06-25 03:45
means that the local variable `path` is undefined.

abubics
2019-06-25 03:45
you're importing it through a destructure (as `{ path }`)

abubics
2019-06-25 03:45
so that line is probably not doing what you want

abubics
2019-06-25 03:46
in a project I have lying around (recent-ish), I have it without the destructure: ``` const path = require('path'); ```

mui_ume
2019-06-25 03:46
got it thanks Boris

mui_ume
2019-06-25 03:46
it passed, now it is the issue publisher.publishPacts(opts).then(() => console.log('Pacts successfully published')); ^ TypeError: Cannot read property 'publishPacts' of undefined at Object.<anonymous> (/Users/tohlaymui/Desktop/tl_stella-client_app/pact/publish.js:13:11) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)

mui_ume
2019-06-25 03:47
same issue as you mentioned :slightly_smiling_face:

abubics
2019-06-25 03:48
yep, looks like exactly the same symptom

mui_ume
2019-06-25 03:48
now I got this message out ```> node ./pact/publish.js [2019-06-25T03:47:20.723Z] INFO: pact-node@8.6.0/7286 on LayMui.local: Publishing Pacts to Broker [2019-06-25T03:47:20.726Z] INFO: pact-node@8.6.0/7286 on LayMui.local: Publishing pacts to broker at: https://tl.pact.dius.com.au/ [2019-06-25T03:47:20.732Z] INFO: pact-node@8.6.0/7286 on LayMui.local: Created './standalone/darwin-1.68.0/bin/pact-broker publish '/Users/tohlaymui/Desktop/tl_stella-client_app/pacts' --broker-base-url 'https://tl.pact.dius.com.au/' --consumer-app-version '2.0.0'' process with PID: 7287 [2019-06-25T03:47:33.513Z] WARN: pact-node@8.6.0/7286 on LayMui.local: Pact exited with code 1. [2019-06-25T03:47:33.513Z] ERROR: pact-node@8.6.0/7286 on LayMui.local: Could not publish pact: Error making request - SocketError getaddrinfo: nodename nor servname provided, or not known /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.68.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 1 of 3 Error making request - SocketError getaddrinfo: nodename nor servname provided, or not known /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.68.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 2 of 3 Error making request - SocketError getaddrinfo: nodename nor servname provided, or not known /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.68.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 3 of 3 Failed to publish MyConsumer/MyProvider pact due to error: SocketError - getaddrinfo: nodename nor servname provided, or not known```

mui_ume
2019-06-25 03:50
I need to source my .env which defined the authentication PACT_USERNAME, PACT_PASSWORD

abubics
2019-06-25 03:52
that's right, if you don't have the vars in your env before running `publish.js`, they'll be undefined :ok_hand:

mui_ume
2019-06-25 03:53
```[2019-06-25T03:50:04.435Z] INFO: pact-node@8.6.0/7334 on LayMui.local: Publishing Pacts to Broker [2019-06-25T03:50:04.437Z] INFO: pact-node@8.6.0/7334 on LayMui.local: Publishing pacts to broker at: https://tl.pact.dius.com.au/ [2019-06-25T03:50:04.444Z] INFO: pact-node@8.6.0/7334 on LayMui.local: Created './standalone/darwin-1.68.0/bin/pact-broker publish '/Users/tohlaymui/Desktop/tl_stella-client_app/pacts' --broker-base-url 'https://tl.pact.dius.com.au/' --consumer-app-version '2.0.0'' process with PID: 7335 [2019-06-25T03:50:06.597Z] WARN: pact-node@8.6.0/7334 on LayMui.local: Pact exited with code 1. [2019-06-25T03:50:06.597Z] ERROR: pact-node@8.6.0/7334 on LayMui.local: Could not publish pact: Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ ```

mui_ume
2019-06-25 03:53
I need to login to the pact-broker

mui_ume
2019-06-25 03:56
I still not sure how to use the pact broker to see the publish pact file?

mui_ume
2019-06-25 03:57
If the publishing succeed, I should see something at the pact broker host? https://tl.pact.dius.com.au/

matt.fellows
2019-06-25 03:58
As mentioned, you need to get an API token from the broker settings page, and use the `pactBrokerToken` option (see https://github.com/pact-foundation/pact-js/#publishing-options)

matt.fellows
2019-06-25 03:59
> If the publishing succeed, I should see something at the pact broker host? https://tl.pact.dius.com.au/ Yes

mui_ume
2019-06-25 04:57
I have set the pactBrokerToken ```const publisher = require('@pact-foundation/pact-node'); const path = require('path'); const opts = { providerBaseUrl: 'http://localhost:8080', pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], pactBroker: 'https://tl.pact.dius.com.au/', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, pactBrokerToken: 'EgtLgimSQeaImlMZ4ToqAQ', consumerVersion: '2.0.0', }; publisher.publishPacts(opts).then(() => console.log('Pacts successfully published')); ```

mui_ume
2019-06-25 04:57
but still fail ```[2019-06-25T04:56:08.842Z] WARN: pact-node@8.6.0/4924 on LayMui.local: Pact exited with code 1. [2019-06-25T04:56:08.842Z] ERROR: pact-node@8.6.0/4924 on LayMui.local: Could not publish pact: Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ ```


tjones
2019-06-25 05:05
*it's generally better to use the cli to publish pacts if you can

tjones
2019-06-25 05:09
``` pact-broker publish ./pacts -a 2.0.0 -p "$PACT_PASSWORD" -u "$PACT_USERNAME" -b https://tl.pact.dius.com.au/ ```

tjones
2019-06-25 05:09
^ This line does the same as your example

tjones
2019-06-25 05:12
Do we have a way of taking a JS object and seeing if it matches the result from matchers? For example: ``` const pactResponseBody = { filenames: eachLike('foo.jpg'), }; const mockResponseBody = { filenames: [ "a.gif", "bar.jpg" ], }; const otherResponseBody = { some: { other: { structure:[ "a.gif", "bar.jpg" ], }, }, }; if (/* mockResponseBody matches pactResponseBody */) {} // true if (/* otherResponseBody matches pactResponseBody */) {} // false ``` is there anything I can put in the `if` to achieve this?

mui_ume
2019-06-25 05:13
I Need to install pact-broker?

tjones
2019-06-25 05:15
no, the cli tools come with `@pact-foundation/pact-node` as binstubs. You can put the command above in a script in `package.json`

tjones
2019-06-25 05:15
Note that your script actually publishes the same version every time

tjones
2019-06-25 05:15
you need some way to locally determine the version

mui_ume
2019-06-25 05:18
like this : "publish:pact": "pact-broker publish ./pacts -a 2.0.0 -p "$PACT_PASSWORD" -u "$PACT_USERNAME" -b https://tl.pact.dius.com.au/"

tjones
2019-06-25 05:18
And, if we don't have this, should we?

mui_ume
2019-06-25 05:21
didn't work as well, I got this error ```> pact-broker publish ./pacts -a 2.0.0 -p $PACT_PASSWORD -u $PACT_USERNAME -b https://tl.pact.dius.com.au/ Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! tlstellaclientapp@0.0.1 publish:pact: `pact-broker publish ./pacts -a 2.0.0 -p $PACT_PASSWORD -u $PACT_USERNAME -b https://tl.pact.dius.com.au/` npm ERR! Exit status 1 ```

mui_ume
2019-06-25 05:21
maybe I try to use my own local pact broker? without any authentication?

tjones
2019-06-25 05:21
The use case is for mocking the response from the API layer outside pact tests (but keeping them in sync with pact tests). to avoid this: ``` const someApiCall() = {/* .... */}; describe("pact test", () => { /* asserts that someApiCall() calls the provider in some way, and returns some object foo to the caller */ }) describe("unit test for caller", ()=> { /* mocks someApiCall() as returning some object bar, and asserts that the rest of the code behaves */ }) ``` In this situation, all tests could be green, even if there's actually a failure (since the `someApiCall()` actually returns a different object to the one tested in the unit tests for the call site)


mui_ume
2019-06-25 05:24
I copy the token at Read only token (developer)?

tjones
2019-06-25 05:24
You need the read/write token to publish

tjones
2019-06-25 05:25
Also, in the output that you sent above, you're not using the API token ,you're using the username and password

tjones
2019-06-25 05:25
see the second link above for the options for `pact-broker publish`

mui_ume
2019-06-25 05:30
```> tlstellaclientapp@0.0.1 publish:pact /Users/tohlaymui/Desktop/tl_stella-client_app > pact-broker publish ./pacts -k 'aF5qJ0rVTGlYQNe280IAAQ' -a 2.0.0 -p $PACT_PASSWORD -u $PACT_USERNAME -b https://tl.pact.dius.com.au/ Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published```

mui_ume
2019-06-25 05:30
I copied the token from the Read/Write token (CI), still have the Authentication Failed Error

tjones
2019-06-25 05:30
you probably need to not specify the username and password

tjones
2019-06-25 05:30
we should make that clear in the documentation

mui_ume
2019-06-25 05:31
got it

mui_ume
2019-06-25 05:31
```> tlstellaclientapp@0.0.1 publish:pact /Users/tohlaymui/Desktop/tl_stella-client_app > pact-broker publish ./pacts -k 'aF5qJ0rVTGlYQNe280IAAQ' -a 2.0.0 -b https://tl.pact.dius.com.au/ Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ The latest version of this pact can be accessed at the following URL (use this to configure the provider verification): https://tl.pact.dius.com.au/pacts/provider/MyProvider/consumer/MyConsumer/latest LayMui:tl_stella-client_app tohlaymui$ ```

mui_ume
2019-06-25 05:46
I can't seem to run pact-broker in the command line

mui_ume
2019-06-25 05:46
pact-broker describe-version -b https://tl.pact.dius.com.au/ -a MyConsumer,MyProvider

mui_ume
2019-06-25 05:46
trying to use this command line to get the version?

tjones
2019-06-25 05:47
That's because it's included as a binary through npm, it's not on the path

tjones
2019-06-25 05:48
you can find it in `node_modules/.bin`

tjones
2019-06-25 05:49
That command will get the version that the broker knows about

tjones
2019-06-25 05:49
My comment above was that your script would have published the same application version every time

tjones
2019-06-25 05:50
I/we can't tell you how to determine what your application version is, because it's up to you and your team

tjones
2019-06-25 05:50
see https://docs.pact.io/getting_started/versioning_in_the_pact_broker for some guidelines on how versioning works in Pact

matt.fellows
2019-06-25 05:58
I think you can call `getValue()` on them to get the value _sans_ matcher guff, but from memory that?s not recursive for deeply nested matchers

matt.fellows
2019-06-25 05:58
`extractPayload(pactResponseBody)` will do the same, but recursive

matt.fellows
2019-06-25 05:59
I think what you?re asking is not currently possible (because you won?t be able to do an equality check), but is intriguing

tjones
2019-06-25 07:57
I think `extractPayload` gives me the raw json (useful to achieve the goal, but not what I'm asking for). Is that right?

tjones
2019-06-25 07:58
I'd like to have a few different ways of doing this, so that Pact's opinions don't bleed into the unit test suite

matt.fellows
2019-06-25 10:39
Yep, extract payload would turn: ``` eachLike({ foo: term({generate: "bar", matcher: "[?regex?]"}), baz: [ "bats" ] }) ``` into: ``` [{ foo: "bar", baz: [ "bats" ] }] ```

matt.fellows
2019-06-25 10:46
So basically what you want is the ability to apply a pact matcher in unit test?

dalsidhu99
2019-06-25 12:08
hi all, my test is failing add this level - service.addInteraction(interaction);

dalsidhu99
2019-06-25 12:08
could this be something to do with the mock server?

matt.fellows
2019-06-25 12:09
What's the actual error. Have you enabled debug logs and followed the troubleshooting section of the readme?

dalsidhu99
2019-06-25 12:17
this is what i get - "You must provide a description for the interaction."

matt.fellows
2019-06-25 12:36
There's your answer. You're missing a required field on the interaction object

alessandrobuggin
2019-06-25 14:13
has joined #pact-js

dalsidhu99
2019-06-26 22:00
hi there, when we have published tests to the broker, how do we get tests replayed on the provider side? thanks

matt.fellows
2019-06-26 22:01
What have you tried?

matt.fellows
2019-06-26 22:01
Are the examples in the repo not clear?

whitehorse5353
2019-06-27 16:57
has joined #pact-js

whitehorse5353
2019-06-27 16:58
Hi All, i am having a weird issue my query param is around 2588 char length of base65 encoded string some home pact breaks the url query param into two portions and fails my test any idea anyone ?

whitehorse5353
2019-06-27 17:00
versions of my package @pact-foundation/pact: 5.9.1 @pact-foundation/pact-node: 6.19.7

matt.fellows
2019-06-28 00:06
Hi Lokesh. Firstly, have you tried upgrading to a latter version of Pact? (yours is quite old)

matt.fellows
2019-06-28 00:06
secondly, please provide a reproducable example so we can help, or at the very least a stack trace / error log

tjones
2019-06-28 01:27
Yes. Often the response you expect from the API layer is the same as the json on the wire. So, you could write: ``` const pactBody = eachLike({ foo: term({generate: "bar", matcher: "[?regex?]"}), baz: [ "bats" ] }); /* ... */ expect(someApiCall()).toEqual(extractPayload(pactBody)); ```

tjones
2019-06-28 01:28
or perhaps even nicer: ``` expect(someApiCall()).toMatchPactResponse(pactBody); ```

doxuantien
2019-06-28 03:34
has joined #pact-js

vitaliy.grigoruk
2019-06-28 07:14
pact plugin for `chai`? :slightly_smiling_face:

rafael.anachoreta
2019-06-28 09:15
Was looking into this just now! I second that there is some demand for v3 in pact-js :slightly_smiling_face: And thanks for sharing the approach above

whitehorse5353
2019-06-28 23:55
Hi @matt.fellows, sorry that was my mistake and it's resolved now thanks :slightly_smiling_face:

tjones
2019-06-30 23:20
@yousafn and I have been working on a Jest wrapper

tjones
2019-06-30 23:20
but we haven't done anything for expect yet

tjones
2019-06-30 23:21
it would be easy to extend / modify what we currently have for other test frameworks (I think it currently works with anything Jasmine based)

mui_ume
2019-07-01 03:23
I like to check if my provider is more than 1, how do I specify in my pactSetup file, current pactSetup.js file ```// ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.port = 8080; global.provider = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Platform Services', host: '127.0.0.1', }); ```

mui_ume
2019-07-01 03:23
my consumer is the UI app, it will talk to a few backend services. how do I specify that in the pactsetup file? thanks

bethskurrie
2019-07-01 03:24
you make one configuration for each provider

bethskurrie
2019-07-01 03:24
global.provider1 = ... global.provider2 = ...

bethskurrie
2019-07-01 03:25
But use the real name of your provider instead of `provider1`. eg `global.platformServices`

mui_ume
2019-07-01 03:29
let me redo my pact/setup.js ...

mui_ume
2019-07-01 03:31
```// ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.port = 8080; global.platformServices = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', PlatformServices: 'Platform Services', host: '127.0.0.1', }); global.LENS = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', LENS: 'LENS', host: '127.0.0.1', }); ```

mui_ume
2019-07-01 03:31
is it like this?

mui_ume
2019-07-01 03:32
or it's in the same file or separate setup files?

bethskurrie
2019-07-01 03:33
whatever works for you.

bethskurrie
2019-07-01 03:33
just make sure it's required before you run the test that uses it

bethskurrie
2019-07-01 03:33
you'll need to put them on different ports.

mui_ume
2019-07-01 03:34
I see what you mean now thanks

mui_ume
2019-07-01 04:00
do I need to specify different global.port for different provider?

bethskurrie
2019-07-01 04:00
yes

bethskurrie
2019-07-01 04:00
you can't run two processes on the same port

mui_ume
2019-07-01 05:25
can I check? what is the spec:2 means?

matt.fellows
2019-07-01 05:28
It says what specification of the Pact framework to use. The specification is what defines what features are compatible across language implementations. Most support v2, Pact JVM has some advanced features (e.g. mulitple provider states, ability to pass parameters with the states) that are only available in v3+. So if you need a pact file to interop across languages, you need to make sure you only use features the other languages support. It actually defaults to 2 anyway

mui_ume
2019-07-01 05:34
thanks. my pact framework will need to have mulitple language support. my consumer is in JS, my provider can be in Java, C# or C++, so I need to set to 3?

matt.fellows
2019-07-01 05:38
no, JS and .NET only supports 2. I?d stick with 2

mui_ume
2019-07-01 05:39
okay, I change my pactSetup.js to configure for multiple provider like this: ```global.portIM = 8080; global.portSM = 8082; global.portCM = 8083; global.hostIM = '127.0.0.1'; global.hostSM = '127.0.0.2'; global.hostCM = '127.0.0.3'; global.IdentityManager = new Pact({ cors: true, port: global.portIM, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Identity Manager', host: global.hostIM, }); global.SessionManager = new Pact({ cors: true, port: global.portSM, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Session Manager', host: global.hostSM, }); ```

mui_ume
2019-07-01 05:40
in my consumer test, I change this baseURL like this ```// add expectations it('returns a successfully body', done => axios.request({ method: 'POST', baseURL: `${global.portIM} + ':' + ${global.hostIM}`, url: '/api/identity-manager/v2/login', headers: { Accept: '*/*', 'content-type': 'application/json', }, data: BODY, })```

mui_ume
2019-07-01 05:40
when I run npm run test:pact

mui_ume
2019-07-01 05:41
I got the error: ``` Setting up Pact with Consumer "UI Client" and Provider "Identity Manager" using mock service on Port: "8080" console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: POST /api/identity-manager/v2/login See /Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact.log for details. FAIL App/Screens/Login/__tests__/login.service.test.pact.js (21.948s) LoginService API login request ? returns a successfully body (20073ms) ```

matt.fellows
2019-07-01 05:42
what does the log file say

mui_ume
2019-07-01 05:44
```W, [2019-07-01T13:43:37.282865 #8497] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /api/identity-manager/v2/login W, [2019-07-01T13:43:37.282959 #8497] WARN -- : Missing requests: POST /api/identity-manager/v2/login ```

mui_ume
2019-07-01 05:45
wait, I miss out the http...

mui_ume
2019-07-01 05:47
baseURL: `'http' + ${global.portIM} + ':' + ${global.hostIM}`,

mui_ume
2019-07-01 05:47
I need to fix this line...

tjones
2019-07-01 05:49
You have also got `port` and `host` the wrong way around - it should be: ``` baseUrl: `http://${global.hostIM}:${global.portIM}` ```

tjones
2019-07-01 05:49
host goes before port

mui_ume
2019-07-01 05:52
thanks, it works now :slightly_smiling_face:

mui_ume
2019-07-03 13:55
when I run npm run test to run my jest (react-native), it got into the pact test and fail

mui_ume
2019-07-03 13:55
```npm run test > tlstellaclientapp@0.0.1 test /Users/tohlaymui/Desktop/tl_stella-client_app > jest PASS App/Utils/DataBindings/__tests__/valueRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/appVariableRegexProcessor.js PASS App/Utils/DataBindings/__tests__/appendRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/removeRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/containsInProcessor.test.js PASS App/Utils/DataBindings/__tests__/formSubmitWithTypeRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/sourceRegexProcessor.test.js FAIL App/Screens/Login/__tests__/login.service.test.pact.js (7.212s) ? LoginService API ? login request ? returns a successfully body TypeError: Cannot read property 'addInteraction' of undefined 42 | }, 43 | }; > 44 | return global.IdentityManager.addInteraction(interaction); | ^ 45 | }); 46 | 47 | // add expectations at Object.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:44:37) ? LoginService API ? login request ? returns a successfully body Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout. 46 | 47 | // add expectations > 48 | it('returns a successfully body', done => axios.request({ | ^ 49 | method: 'POST', 50 | baseURL: `http://${global.hostIM}:${global.portIM}`, 51 | url: '/api/identity-manager/v2/login', at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:85:20) at Suite.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:48:5) at Suite.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:23:3) at Object.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:7:1) Test Suites: 1 failed, 7 passed, 8 total Tests: 1 failed, 10 passed, 11 total Snapshots: 0 total```

mui_ume
2019-07-03 13:55
here is my package.json: ``` "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "lint": "eslint App/", "react-devtools": "react-devtools", "test": "jest", "test:pact": "jest cross-env CI=true __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch \"**/*.test.pact.js\"", "publish:pact": "pact-broker publish ./pacts -a 2.0.0 -b https://pact.shared.frigg.li/" },```

mui_ume
2019-07-03 13:57
but if I do npm run test:pact it passed: ``` > tlstellaclientapp@0.0.1 test:pact /Users/tohlaymui/Desktop/tl_stella-client_app > jest cross-env CI=true __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch "**/*.test.pact.js" [2019-07-03T13:56:50.701Z] INFO: pact-node@8.6.0/9754 on LayMui.local: Creating Pact Server with options: consumer = UI Client, cors = true, dir = /Users/tohlaymui/Desktop/tl_stella-client_app/pacts, host = 127.0.0.1, log = /Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact.log, pactFileWriteMode = update, port = 8080, provider = Identity Manager, spec = 2, ssl = false, sslcert = , sslkey = [2019-07-03T13:56:50.703Z] INFO: pact-node@8.6.0/9754 on LayMui.local: Creating Pact Server with options: consumer = UI Client, cors = true, dir = /Users/tohlaymui/Desktop/tl_stella-client_app/pacts, host = 127.0.0.2, log = /Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact.log, pactFileWriteMode = update, port = 8082, provider = Session Manager, spec = 2, ssl = false, sslcert = , sslkey = [2019-07-03T13:56:50.703Z] INFO: pact-node@8.6.0/9754 on LayMui.local: Creating Pact Server with options: consumer = UI Client, cors = true, dir = /Users/tohlaymui/Desktop/tl_stella-client_app/pacts, ```

matt.fellows
2019-07-03 22:06
Why is IdentityManager undefined? ` TypeError: Cannot read property 'addInteraction' of undefined`.

matt.fellows
2019-07-03 22:07
oh I see

matt.fellows
2019-07-03 22:07
what is your question? Something you?re doing with `npm run test:pact` is setting IdentityManager (presumably a file that does some setup e.g. `pactSetup.js `)

matt.fellows
2019-07-03 22:08
And when you run `npm run test` it?s not configuring it

mui_ume
2019-07-04 10:46
this is fixed by using a different folder name for pact test. so I used __pact-tests__ instead of __tests__

thamu.gurung
2019-07-08 20:01
has joined #pact-js

fraser.crichton.devel
2019-07-09 00:29
has joined #pact-js

craig.pothier
2019-07-09 15:17
has joined #pact-js

yousafn
2019-07-09 16:50
Ola all, When performing pact-verification, if we are using `pactUrls` to read from a local file, how can we publish the verification results to the pact broker? If I specify a `pactBrokerUrl`, then the local pacts are read, and also the pacts read from the pact-broker. I only want to read from the local pacts, and publish the verification results up to the broker. Basically I am 1. Downloading a pact for a given consumer/provider pair by tag, via axios into a local file 2. I then parse the local json file, and pull out the path/request/body and use aws4 to sign the request 3. I then inject the modified headers back into the pact file 4. I run my provider verification, using `pactUrls` to point to my local version of the file 5. to close the loop, I want to publish the verification results back up to the broker. It follows on my from my issue raised here https://github.com/pact-foundation/pact-js/issues/304 and my workaround is similar to that proposed by @bernardo.guerreiro in his medium article here https://medium.com/dazn-tech/pact-contract-testing-dealing-with-authentication-on-the-provider-51fd46fdaa78

yousafn
2019-07-09 16:53
ahhh looking at this https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-results it seem?s that it is not possible ``` Note that you can only publish verification results for pacts that were retrieved from a pact broker. You cannot publish results for local pact files. ``` :disappointed:

matt.fellows
2019-07-09 21:15
If you?re pulling from the broker in the first place, it should have the HAL links in them containing paths to the broker

matt.fellows
2019-07-09 21:16
that?s all the verifier needs to be able to publish the results

matt.fellows
2019-07-09 21:17
i.e. if you run `curl -v https://test.pact.dius.com.au/pacts/provider/Van-test_bobby/consumer/Van-test_billy/latest --user dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1 | jq .` you can see the `pb:publish-verification-results` link. If you retain those you should be golden

yousafn
2019-07-10 07:42
Fab!! Cheers homie, I shall give that a go when I am in work shortly! Nice one!!!

yousafn
2019-07-10 09:46
That works perfectly matey, nice one for that :ok_hand:

matt.fellows
2019-07-10 10:47
SWEET!

matt.fellows
2019-07-10 10:47
you?re welcome

yousafn
2019-07-10 10:57
I?ll get an example up in my public repo at some point, so I can share back my solution with the community! Holding a pact-party with my client soon, in order to get them fully on board with pact, they can see the value in theory, but just need to show them it working in practise now on their end. Will probably write up some more slides, so will share them out too in another blog post

matt.fellows
2019-07-10 11:20
Thanks man

matt.fellows
2019-07-10 11:21
We?ve been discussing internally how the removal of the ?completely? free open-source hosted tier of http://Pactflow.io (i.e. what was previously the beta) might effect adoption etc. If in those discussions you run into issues, please let us know. We?re still figuring out what the best approach is from a commercial and community perspective, and real-life feedback is the best!

yousafn
2019-07-10 11:24
no worries mate, I?ve got an open source version of pactflow but not currently pumping any contracts into it, just haven?t taken the time to do so. If you want me to do so, so I can let you know if it goes up/down, then I can switch over my OS CI jobs to point at the pact-flow version today

matt.fellows
2019-07-10 11:25
ha, well hopefully we can do better than have our customers tell us when its down :stuck_out_tongue:

matt.fellows
2019-07-10 11:26
This is more of the adoption question - we work for a consultancy too and often we get asked to, or implement Pact during the course of delivery. It was really nice to just sign up for another free hosted broker for clients and just get cracking, rather than having to run a broker internally, manage it etc.

matt.fellows
2019-07-10 11:27
We?ve removed the ?free for all? plan, which changes that conversation a bit

matt.fellows
2019-07-10 11:27
all good, just know we?re here

yousafn
2019-07-10 11:44
Hmmm, I think in order to drive paid for adoption, providing a 2/4 week trial, similar to most other paid for tools would be preferable, It would allow companies to get time to implement a workflow and see how it pans out, and then as they will have the infra in place, it should be easier to get the beancounters to open their wallets and pay you money! It?s so trivial to spin up pact broker via docker, and postgres. pretty much all of our clients use AWS so sticking PB on an ecs cluster, and postgres is RDS means it?s pretty self managed anyway, and I imagine most of these teams have devops. A 4 week trial would probably give a team enough time to get the consumers and providers on board for at least a couple of services and start seeing enough of a benefit.

matt.fellows
2019-07-10 11:45
Thanks, sorry I probably wasn?t clear. I?m _not_ asking for you to help sell Pactflow (but, that would be great if that?s something that naturally comes up because it somehow helps you). I just mean Pact adoption here - the less things that need to be done to get started playing with Pact == higher chance of adoption

matt.fellows
2019-07-10 11:46
but your points taken

yousafn
2019-07-10 15:02
`I'm _not_ asking for you to help sell Pactflow` - I didn?t get that from your message, sorry if my reply sounded like I took that from your comment, I have just always been (sometimes wrongly) overly opinionated

matt.fellows
2019-07-10 21:42
You mean you're a _consultant_ :yum:

mui_ume
2019-07-11 03:49
I got a question on pact. in my consumer's pact test, I specify my expected body's content example: ``` const EXPECTED_BODY = { authToken: 'eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyMTVhMGVhZS00ZjkwLTRlODItOWY4Zi1lNzhlOTdkMzcyODAiLCJldmVudF9pZCI6IjQxMjA3MjQwLWI2NGEtNDYxNi1iOGFiLTJkYzNiZjY4YWEwNCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE1NjEwOTUwMDYsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0yX2EzbE5SRU5QMSIsImV4cCI6MTU2MTA5ODYwNiwiaWF0IjoxNTYxMDk1MDA2LCJqdGkiOiJlNGFiNTI0Ny1hZjgwLTQ1MmUtOTcwMS01YjQ4OTY1ZTcwZDgiLCJjbGllbnRfaWQiOiI2Z2xwbmRxb2s2YWhua3M2dGFnNXQ5cGMwZyIsInVzZXJuYW1lIjoicWFAdGVsZXBhdGh5LmFpIn0.icFT50MVM-xhAPIu76H9XwIeNHhbe6_d3LcAv1qDQcRp1xabxpgzntgaEvyUnaTwFFJzkU2flfIrT_Y8TCeeFFqMFrMkpS9GadVtraxpOtNhMwxrwUz6bbz8iMHFxSxcIi0Ar3y06RLoRkp3C4gXf7eL8JXsTI9IB56TK7idvUmUcbN_322UPsAU98l3XFjdQEkMo3Fnqyrr41ftWBH876E2KB4g79Q73AL_s0j7mRmXjGswu8-pFiyPcIrDZKz35RSEpdWYLoRyW8rDnYU6YqWM-ncXEczBKlBKk6ggxMOK_qcTc7HYBty9c16zOn-33hxLCxG6pOtg5vLD3L0Tqw', clientInfo: { clientId: '0662923d-b187-4879-866a-3f053178426a', }, };```

mui_ume
2019-07-11 03:50
what happen if this expected body's value is dynamic? the provider may return different value. how do I check this in my code?

matt.fellows
2019-07-11 03:53
look into matchers

mui_ume
2019-07-11 05:18
thanks will ask my developer to check that out

mui_ume
2019-07-12 08:06
Hi, I am adding the pact test at the consumer and talk to a few services -Identity Manager, Session Manager, etc. do I have only 1 pact file for all the tests?

matt.fellows
2019-07-12 08:06
no, 1 pact per consumer-provider pair

mui_ume
2019-07-12 08:13
is my pactTestWrapper.js correctly specified: ```jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; beforeAll((done) => { global.IdentityManager.setup().then(() => done()); global.SessionManager.setup().then(() => done()); }); afterEach((done) => { global.IdentityManager.verify().then(() => done()); global.SessionManager.setup().then(() => done()); }); afterAll((done) => { global.IdentityManager.finalize().then(() => done()); global.SessionManager.setup().then(() => done()); }); ```

mui_ume
2019-07-12 08:14
oh I just spot my mistakes, :slightly_smiling_face:

matt.fellows
2019-07-12 08:14
no

matt.fellows
2019-07-12 08:14
ha

matt.fellows
2019-07-12 08:14
:slightly_smiling_face:

matt.fellows
2019-07-12 08:15
aside from the `setup` being in the wrong place, the other issue is that you have two promises that call the same `done()`

matt.fellows
2019-07-12 08:16
this will potentially lead to issues where one promise finishes earlier than the other and ?cuts off? the other promise from doing it?s job

matt.fellows
2019-07-12 08:16
you need to wait for all promises and _then_ call done

matt.fellows
2019-07-12 08:17
``` beforeAll((done) => { Promise.all([ global.IdentityManager.setup(), global.SessionManager.setup() ]) .then(done) }); ```

matt.fellows
2019-07-12 08:17
something like that would be better, because if one of the promises fail you?ll get the error.

mui_ume
2019-07-12 08:31
I got this error ```App/Screens/Login/__pact-tests__/IdentifyManager.login.test.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 22 | afterAll((done) => { 23 | Promise.all([ > 24 | global.IdentityManager.finalize(), | ^ 25 | global.SessionManager.finalize(), 26 | global.ConversationManager.finalize(), 27 | ]) ```

mui_ume
2019-07-12 08:46
```W, [2019-07-12T16:45:15.388695 #29299] WARN -- : Could not load existing consumer contract from /Users/tohlaymui/Desktop/tl_stella-client_app/pacts/ui_client-identity_manager.json due to 757: unexpected token at 'null'. Creating a new file. I, [2019-07-12T16:45:15.389986 #29299] INFO -- : Verifying - interactions matched E, [2019-07-12T16:45:15.390018 #29299] ERROR -- : 757: unexpected token at 'null' (JSON::ParserError) /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.69.0/lib/vendor/ruby/2.2.0/gems/json-2.2.0/lib/json/common.rb:156:in `parse' /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.69.0/lib/vendor/ruby/2.2.0/gems/json-2.2.0/lib/json/common.rb:156:in `parse' ```

mui_ume
2019-07-12 08:48
do I need to have different pacts folder for each consumer-provider ?

mui_ume
2019-07-12 08:52
I set up my pactSetup.js: ```// ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.portIM = 8080; global.portSM = 8082; global.portCM = 8083; global.hostIM = '127.0.0.1'; global.hostSM = '127.0.0.2'; global.hostCM = '127.0.0.3'; global.IdentityManager = new Pact({ cors: true, port: global.portIM, log: path.resolve(process.cwd(), 'logs', 'pact-IM.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts/IM'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Identity Manager', host: global.hostIM, }); global.SessionManager = new Pact({ cors: true, port: global.portSM, log: path.resolve(process.cwd(), 'logs', 'pact-SM.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts/SM'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Session Manager', host: global.hostSM, }); global.ConversationManager = new Pact({ cors: true, port: global.portCM, log: path.resolve(process.cwd(), 'logs', 'pact-CM.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts/CM'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Conversation Manager', host: global.hostCM, }); ```

mui_ume
2019-07-12 08:52
when I run my pact test, I got this error ```[2019-07-12T08:49:50.295Z] INFO: pact-node@8.6.2/29634 on LayMui.local: Created './standalone/darwin-1.69.0/bin/pact-mock-service service --consumer 'UI Client' --cors 'true' --pact_dir '/Users/tohlaymui/Desktop/tl_stella-client_app/pacts/IM' --host '127.0.0.1' --log '/Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact-IM.log' --pact-file-write-mode 'update' --port '8080' --provider 'Identity Manager' --pact_specification_version '2'' process with PID: 29640 [2019-07-12T08:49:51.336Z] INFO: pact@8.2.6/29634 on LayMui.local: Setting up Pact with Consumer "UI Client" and Provider "Identity Manager" using mock service on Port: "8080" FAIL App/Utils/Api/__pact-tests__/SessionManager.start.test.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 23 | Promise.all([ 24 | global.IdentityManager.finalize(), > 25 | global.SessionManager.finalize(), | ^ 26 | global.ConversationManager.finalize(), 27 | ]) 28 | .then(done); at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.<anonymous> (pact/pactTestWrapper.js:25:25)```

mui_ume
2019-07-12 08:53
why is this pointing to Setting up Pact with Consumer "UI Client" and Provider "Identity Manager" for the provider ConversationManager?

mui_ume
2019-07-12 09:50
I just realise I need to setup for 1 provider. ignore my questions

dalsidhu99
2019-07-14 17:30
hi all, can anyone tell me what I, D and E standfor in the mock server integration log? im guessing I is 'Interaction' and D is 'Differ', no idea about E

dalsidhu99
2019-07-14 17:31
'Error' ?

dalsidhu99
2019-07-14 19:53
Also, i have an installation of pact -foundation/pact 8.2.6 but Matchers dont appear to exist within the pact.d.ts file within the node modules, I can however see this in the pact-foundation/node 5.2.1 installation

dalsidhu99
2019-07-14 19:53
any reason why we dont see it in the 1st?

matt.fellows
2019-07-14 21:17
Log levels - info, debug, error

matt.fellows
2019-07-14 21:18
Can you please show me what you're doing? The examples in the repo use the matchers from the exported library so they definitely work (typescript included)

dalsidhu99
2019-07-14 21:35
all i want to do is add a 'like' Matcher to my interaction

dalsidhu99
2019-07-14 21:36
i thinki have found the solution, 2 min

dalsidhu99
2019-07-14 21:43
thank you, i was having issues earlier being able to require pact matchers in my file, but i have managed to get it working with my interactions :+1:

dalsidhu99
2019-07-16 10:28
Hi there, are there any reporting tools that work well with pact js?

dalsidhu99
2019-07-16 10:31
it would be nice to get feedback from reports other than looking in the pact broker

tjones
2019-07-16 11:03
What sort of reports are you interested in?

dalsidhu99
2019-07-16 12:49
Hi Tim, im thinking a report along the lines of how many tests have been executed and how many have passed/failed

dalsidhu99
2019-07-16 12:49
so we can alert people as soon as there is a failure

dalsidhu99
2019-07-16 12:50
will be useful to display on our monitors

matt.fellows
2019-07-16 20:43
What unit testing framework are you using?

matt.fellows
2019-07-16 20:44
You can just use the standard unit test output format from them

dalsidhu99
2019-07-17 08:36
jest, ah good point, i will have look a bit more deeply into that, thanks!

matt.fellows
2019-07-17 08:36
:+1:

shalygai.a
2019-07-18 13:12
Hi all :slightly_smiling_face: I have a test, which Consumer - js Provider - .Net I use Regex to test my body body: Pact.Matchers.term({ matcher: "(?:true)", generate: "true" }) when starting the test provider I have failures what could be the problem?

matt.fellows
2019-07-18 13:14
Are you matching a boolean?

matt.fellows
2019-07-18 13:14
or a string?

shalygai.a
2019-07-18 13:42
string

matt.fellows
2019-07-18 14:19
What are the valid values?

matt.fellows
2019-07-18 14:21
In any case, check your regexes against http://Rubular.com. they must be in that format

kevin.monteiro
2019-07-18 22:12
has joined #pact-js

mui_ume
2019-07-22 07:48
Hi, is there any example of pact test code on the provider. my provider is in java but I don't quite understand the junit, I like to take a look at provider in JS to understand the concept thanks

mui_ume
2019-07-22 07:49
in junit, here is the link given https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit but I do not understand the @Before, @State, @TestTarget concept

tjones
2019-07-22 07:50
I would ask in #pact-jvm

mui_ume
2019-07-22 07:55
I am asking but like to check out JS provider to get some idea on concept becos I am not familiar with junit nor spring

matt.fellows
2019-07-22 08:05
What?s wrong with the examples on the Pact JS repository?



antonello
2019-07-22 08:24
Then (if you want to understand conceptually the provider verification side in a language you?re more familiar with, I would refer to the docs here: https://github.com/pact-foundation/pact-js )

mui_ume
2019-07-22 08:27
Thanks, can I understand that this state concept, is let's say I login with a valid userID, it will have a response. the provider will verify that response. then I got another state where I login with an empty userID, it will have a negative response. the provider will verify that negative response (this is another state)?

igordezky
2019-07-22 17:56
has joined #pact-js

mui_ume
2019-07-23 05:16
do I add state in this way or use given?

mui_ume
2019-07-23 05:17
```beforeEach(() => { const interaction = { state: 'Start Chat with valid session', uponReceiving: 'id, clientId, session, agentDialog, tenantId, userId, callback, sessionData, conversationId and startTime', withRequest: { method: 'POST', path: urlpath_startChat, headers: { Accept: '*/*', 'Content-Type': 'application/json', }, body: like(BODY), }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: like(EXPECTED_BODY), },````

matt.fellows
2019-07-23 21:21
That works fine. There are two interfaces - the builder pattern and this object pattern

tjones
2019-07-24 01:27
@mui_ume A style comment - the intent of `uponReceiving` is to describe the request. I usually write something like: ``` state: 'The session is valid', uponReceiving: 'A request to start the chat', ```

matt.fellows
2019-07-24 01:27
thanks Tim, I meant to add that but was on mobile and forgot

matt.fellows
2019-07-24 01:27
(I have on a TODO list to write an article that help people think about how to write and structure their BDD-style Pact tests)

tjones
2019-07-24 01:28
That would be awesome!

getsreerag22
2019-07-26 02:32
has joined #pact-js


uglyog
2019-07-28 07:30
When next I have some free time, I'll see about getting some of the V3 matchers and generators working with that test

matt.fellows
2019-07-28 12:55
Awesome! I'll see if I can look this Wednesday when I'm back up to Sydney. That's probably the earliest, otherwise maybe next week

matt.fellows
2019-07-28 12:55
I'll try and put together a Delta so we know what we're aiming for in terms of migration

elineopsommer
2019-07-29 13:56
has joined #pact-js

elineopsommer
2019-07-29 14:21
Hi, I have a pact test like this: ```describe('getRecoloredImage', () => { const imageId = '1'; const expectedResponseBody = new Blob([''], {type: 'image/jpeg'}); beforeAll(() => { return provider.addInteraction({ state: 'provider gets the recolored image', uponReceiving: 'a request to get the recolored image for the given image id', withRequest: createGetRequestOptions( `/drawings/images/${imageId}/recolored/image` ), willRespondWith: { status: 200, headers: { 'Content-Type': 'image/jpeg' }, body: Matchers.like(expectedResponseBody) } }); }); it('should return the recolored version of a given image according to the given parameters', async(() => { service.getRecoloredImage(imageId, machineQualityId, colorSetId, dimensionsInPx).subscribe((blob) => { expect(blob).toEqual(expectedResponseBody); }); })); });``` But it gives me ``` HttpErrorResponse{headers: HttpHeaders{normalizedNames: Map{}, lazyUpdate: null, lazyInit: () => { ... }}, status: 500, statusText: 'Internal Server Error', url: 'http://localhost:9876/drawings/images/1/recolored/image', ok: false, name: 'HttpErrorResponse', message: 'Http failure response for http://localhost:9876/drawings/images/1/recolored/image: 500 Internal Server Error', error: Blob{}}``` I just want to test that I get a blob back from the server to display in my page. Does anyone has an idea why it fails?

tjones
2019-07-30 04:46
500 internal server error from the mock probably means that the request didn't match what you said it would

tjones
2019-07-30 04:52
have a look in the logs to see what the problem was

matt.fellows
2019-07-30 06:43
What's the blob? I'm assuming binary, and you definitely can't apply a matcher to a binary object

elineopsommer
2019-07-30 06:49
The content does not matter, I just want to test that I get a blob back. also without the Matchers.like, so only expectedResponseBody as body gives the same error

elineopsommer
2019-07-30 06:49
I also get nothing in the pact logs

matt.fellows
2019-07-30 07:19
If you remove the `body` in the response, does it start to pass?

matt.fellows
2019-07-30 07:22
How would/does that blob serialise over the wire?

matt.fellows
2019-07-30 07:22
Also, are you using a node package or is this in a Jasmine/browser-based environment?

elineopsommer
2019-07-30 07:42
if I remove the body, the error keeps the same, I use this in an Angular webapp

elineopsommer
2019-07-30 07:43
I can see that the angular http client parses it to a blob, that?s probably the error, but if it is a blob it should not be a problem imo..

matt.fellows
2019-07-30 07:44
Ok blob aside if you've removed it, the error is somewhere else in your code

matt.fellows
2019-07-30 07:44
What does the create get request options thing do?

matt.fellows
2019-07-30 07:44
My suggestion is to strip back your test to something small and working, and then iterate from there

mui_ume
2019-07-30 13:25
Hi,I got this error Missing requests: POST /api/identity-manager/v2/invitation/check?method=undefined Unexpected requests: POST /api/identity-manager/v2/invitation/check?method=undefined when my urlpath is '/api/identity-manager/v2/invitation/check?method=undefined'

mui_ume
2019-07-30 13:25
is it need some escape character for ? and =

matt.fellows
2019-07-30 21:13
That looks perfectly legal to me (from a Pact/API standpoint), but also looks to be a mistake. The `undefined` means you?re not correctly referencing a variable and is simply being sent as a string

abubics
2019-07-30 23:10
While the `undefined` is concerning, the missing and unexpected URLs look the same, so it might be failing to match on other parameters, such as headers

matt.fellows
2019-07-30 23:13
:point_up: that also

tjones
2019-07-31 03:58
We've got doubled up synk warnings from my account and from @mboudreau. Synk seems useful - I think we should create a pact-foundation synk organisation that all maintainers can access.

tjones
2019-07-31 03:58
Thoughts?

matt.fellows
2019-07-31 04:01
:+1:

matt.fellows
2019-07-31 04:01
Do you have access to do that?

tjones
2019-07-31 04:02
not sure

pkuang
2019-08-05 19:34
has joined #pact-js

christophe.leray
2019-08-07 15:44
has joined #pact-js

mui_ume
2019-08-08 10:04
I get this error ```? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 10 | 11 | afterAll((done) => { > 12 | global.Platform.finalize().then(() => done()); | ^ 13 | }); 14 | ```

mui_ume
2019-08-08 10:04
what is likely the cause?

mui_ume
2019-08-08 11:01
found the cause, it's due the port number 8080 I set, changed to another port solved it

dalsidhu99
2019-08-12 15:51
Hi All, Looking for some advice. We have been developing a new API within our team, and because its still new and early on we dont yet have any consumers using the API. I have however created a POC and now integrated Pact to prove its benefits within our framework for contract testing. No one has used Pact in the company before, so its a learning curve for everyone. It also means as a Provider i have written tests that test against the mock, creates and Publishes a Pact file and then runs the interactions against the endpoint set up within our test envt

dalsidhu99
2019-08-12 15:51
The problem is this is not the e2e lifecycle of the Pact testing, as we have omitted the consumer.

dalsidhu99
2019-08-12 15:52
Is it the case where we might have to setup an endpoint to consume the API just to get an e2e up and running?

dalsidhu99
2019-08-12 15:53
I will be grateful of any thoughts/suggestions :slightly_smiling_face:

dalsidhu99
2019-08-12 15:58
i have seen the notes on this https://github.com/pact-foundation/pact_broker but as mentioned we havent yet any consumers of the api

matt.fellows
2019-08-12 22:30
No, you don?t _need_ to create an consumer just for the tests, but you might _like_ to. Sometimes it?s helpful to build a client as an example that you can share with teams when they want to integrate.

matt.fellows
2019-08-12 22:31
You can and probably should continue to publish / retrieve from a broker, because when clients do come on board they can start publishing and you can start validating as soon as they come on board. There is definitely some value in doing that

paras.vora
2019-08-16 12:17
@uglyog This is with regard to https://github.com/pact-foundation/pact-js/issues/278 According to your last comment ` don't call .getBody() on your request and response bodies` what should I expect in request/response otherwise?

matt.fellows
2019-08-16 12:29
I think he meant: ``` .body(this.getRequestBody().asBody()) ``` should just be ``` .body(this.getResponseBody()) // <-- ```

matt.fellows
2019-08-16 12:29
Hence the arrows he provided. I?m just guessing though

paras.vora
2019-08-16 12:33
@matt.fellows Tried doing it, no luck.

paras.vora
2019-08-16 12:34
Re-iterating, consumer here is the `java code` & provider is a `js code`.

paras.vora
2019-08-16 12:35
The same code works fine when both the consumer & provider are `java`.

paras.vora
2019-08-16 12:35
@matt.fellows Can we please re-open the issue?

matt.fellows
2019-08-17 02:40
@paras.vora happy to re-open if you can prove the issue relates to JS. At the moment, you have a Pact file that _doesn?t have any matchers_ in it. So it?s doing a string equality match. The main issue is that something is not correct with your JVM tests, so they aren?t producing a pact file with matchers in it

matt.fellows
2019-08-17 02:40
Until we fix that, the issue is not with the JS library.

matt.fellows
2019-08-17 02:41
after you tried making the above adjustment, did the generated Pact file start to contain matchers? This will help us further diagnose

matt.fellows
2019-08-17 02:41
I understand it?s frustrating, we want to help

uglyog
2019-08-17 05:07
When you use `.body(this.getRequestBody().asBody())` it converts the builder into a plain object for serialization into the body. You loose all the matchers.

paras.vora
2019-08-18 10:01
@matt.fellows This is the generated pact file. I see the below section in it: ``` "matchingRules": { "body": { "$.header": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.footer": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.body": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.page.format": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.page.height": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.page.width": { "matchers": [ { "match": "type" } ], "combine": "AND" } } } ```

matt.fellows
2019-08-18 10:53
Ah! Ok at least we're getting matchers now. So, The JS library doesn't support v3 matchers. Please try using v2 on Pact JVM and generating a new contract, and see if that works

chuck
2019-08-19 01:00
has joined #pact-js

paras.vora
2019-08-19 04:39
@matt.fellows Thanks for the response, below are the too libraries I am using in JVM: ``` testCompile('au.com.dius:pact-jvm-provider-spring_2.12:3.5.14',) { exclude group: "org.codehaus.groovy", module: "groovy-all" } ``` ``` compile("au.com.dius:pact-jvm-consumer-junit_2.12:3.5.14",) { exclude group: "org.codehaus.groovy", module: "groovy-all" } ``` Below is what is used in the JS: ``` "@pact-foundation/pact": "^9.0.1", ```

paras.vora
2019-08-19 04:40
Could you please help with the correct compatible versions?

uglyog
2019-08-19 04:50
@paras.vora in your consumer pact test in Java, you would have created an instance of PactProviderRuleMk2. One of the parameters you can provide to the constructor is PactSpecVersion. Setting it to PactSpecVersion.V2 will make the generated pact file compatible with Pact-JS

paras.vora
2019-08-19 06:21
@matt.fellows / @uglyog thanks for the help, that worked. :+1:

matt.fellows
2019-08-19 06:41
:ok_hand::the_horns:

philusd
2019-08-20 11:48
has joined #pact-js

philusd
2019-08-20 11:49
I have a question or rather something I have found with: YOU54F/jest-pact. You can setup cors with your pactoptions although it is not defined in the type and gives an error, but it works. Is that intended?

yousafn
2019-08-20 14:05
Hey, Wasn?t done by design. The pactOptions jest-pact exposes are ``` export interface PactOptions { provider: string; consumer: string; port?: number; logLevel?: LogLevel; pactfileWriteMode?: PactFileWriteMode; dir?: string; } ``` which is a subset of the pactOptions exposed in pact-js This is why you will probably see a compiler error from TypeScript, but it will be passed through to pact-js and work as intended. Feel free to open a PR against jest-pact to allow the cors options in the pactoptions object https://github.com/YOU54F/jest-pact/blob/f542cfca89e9675dd47bbbc5071ce279a5a0760e/src/index.ts#L4

bernardo.guerreiro
2019-08-20 17:19
Hey guys, I am trying to implement Pact between a consumer and provider that communicate through a WebSocket connection. I have read the examples provided, but still have some questions, and there isn?t a lot of writings on this online (might be something I?ll tackle once I?m done). Maybe these questions come from the fact that they apply more to a messaging queue than my exact case. Questions: - The handler function that is given in the example is the already existing handler logic in your consumer? Or is it a handler function that you write that wraps around some logic on the consumer? - Assuming it?s the existing handler function, does that means it needs to necessarily be doing validation of the incoming message? And that?s the part we care about, and mock everything else, if possible? - Where exactly do you test the consumer?s business logic on top of that message? Is that something you simply don?t care about?

matt.fellows
2019-08-21 09:57
Hello, and no, they?re all good questions!

matt.fellows
2019-08-21 10:05
At the moment (at least) we don?t properly support WebSockets as a first class thing.

matt.fellows
2019-08-21 10:05
we support it like other _message like_ interactions as you?ve noted

matt.fellows
2019-08-21 10:06
the standard pattern here is to abstract your protocol handler (i.e. the thing that can talk websockets) from your code that sends or receives a message

matt.fellows
2019-08-21 10:07
I like the ports and adapters metaphor (Alastair Cockburn) to describe this. See slide 20 of a talk I did recently that might help visualise this for you: https://www.slideshare.net/DiUSComputing/serverless-microservices-test-smarter-not-harder/20?src=clipshare

matt.fellows
2019-08-21 10:15
In that terminology, I?d be creating a ?port? that knows what to do with the message, but doesn?t know about the websockets protocol and a separate ?adapter? that performs the conversion. The adapter doesn?t perform business validation, but obviously will need to do basic protocol validation (is it a valid WS interaction / JSON object etc.) This has multiple benefits, but in our case it makes our code more testable. You might be able to use this ?port? (function) directly as the handlers to the message testing framework, or you may need to create a small adapter for the test framework.

matt.fellows
2019-08-21 10:15
> And that?s the part we care about, and mock everything else, if possible? I?d mock out any external dependencies, yes. But that?s a general Pact guideline

matt.fellows
2019-08-21 10:18
> Where exactly do you test the consumer?s business logic on top of that message? Is that something you simply don?t care about? It depends on how much you want the pact test to cover. I?m assuming you probably have other tests that do all of the key business/functional logic. So really all you want to test here is what is relevant for the _contract_, specific to this collaboration.

matt.fellows
2019-08-21 10:21
Generally, for this sort of thing, is that it will take an input (the message), correctly understand it, and perform some action. That might be to write to a DB or to call out to another thing. I?d mock those other things out, and ensure the key things happened. Because for every functional test you do, you need another Pact test, that is a way to find a smell. You only want one Pact test for each message shape - so if you?re finding yourself with multiple identical messages to test what you?re doing, step back

dglaubman600
2019-08-22 02:26
has joined #pact-js

bernardo.guerreiro
2019-08-22 07:06
Hey Matt. Thank you so much for the quick an detailed response (as usual)! I?ll try and see if this can be applied to our current setup, then. I think I was on the right track already, but it sounds like I will indeed need to create my own adapter for the test.

dglaubman600
2019-08-23 04:55
We use PACT in building our microservice-based app (Vue.js front end hitting Kotlin/JVM services) Was very interested to read: https://blog.pactflow.io/injecting-values-from-provider-states/ Is this feature (generators) supported in current versions of Pact-js and pact-jvm?

uglyog
2019-08-23 04:57
Only in Pact-JVM and in the Rust implementation

matt.fellows
2019-08-23 04:58
The best way for us to know how popular/wanted a feature is for it to appear and be requested on GitHub. So if you'd be so kind as to raise it on GH that would help us prioritise our efforts

bethskurrie
2019-08-23 04:59
We already have many issues requesting v3.

matt.fellows
2019-08-24 03:03
true, albeit not this specific feature (in fact looking through the PactJS issues it?s not there at all. I might raise an Epic to start tracking all of the sub features so we can prioritise and commit against it

joao
2019-08-29 13:35
has joined #pact-js

enrique
2019-08-29 15:17
has joined #pact-js

jing.song
2019-08-29 23:59
has joined #pact-js

robin
2019-09-09 15:05
Hello ! I?ve been working on our test suite for a few weeks and discovered recently Pact and decided to implement it on most of our services. I?ve started by testing our public API which has one provider, our backend. I?ve split the tests among 5 different files, one for each endpoint, and each with their own mock server. The tests are executed sequentially. Following the documentation, I?ve made sure to delete the `pacts` folder before running tests and set the `pactFileWriteMode` to `merge`. However, it appears that only the interactions contained in the last test file are written in the pact file. It seems like it?s overwriting itself. I?ve also seen on the documentation that each mock server should run on its own port however I?m not sure how to do that since I?m testing different endpoints with or without interactions with the same provider (hence, same port). I could change the environment variables after each mock server setup to match the mock server?s port but that seems ugly. Is there something I?m missing here? I?ve also started to think about merging all test files together to have a single provider but that?ll be definitely messy (and I?ve got different versions for each endpoints to test?)

matt.fellows
2019-09-10 02:59
Does the ava example in the pact js repository work for you?

matt.fellows
2019-09-10 02:59
it sounds like there is a setup issue somewhere

matt.fellows
2019-09-10 02:59
> I?ve also seen on the documentation that each mock server should run on its own port Only if they need to run in parallel (because obviously you can?t have conflicting ports). If run serially as you say, it should be fine

matt.fellows
2019-09-10 03:00
Just also make sure that each tests makes the call to `finalize` so that the pact is written

robin
2019-09-10 08:27
Hi Matt, thanks for your answers. I?ve checked all the examples, including the ava example. My setup is very similar to the example with the difference that my tests run sequentially and not parallel

robin
2019-09-10 08:32
Right now I?ve got 6 files, testing 5 endpoints, all following the same logic. ``` describe('endpoint /xyz tests') { before => init server, add any external mocks needed, setup provider describe('testing v... for specific endpoint') { before => add needed interactions Then test endpoints & interactions after => verify interactions } after => finalize }```

robin
2019-09-10 08:34
I?ve also did several checked, removing one test of the sequence or just testing it indvidually. Pacts are written but when running sequentially, they seem to be overwritten

tjones
2019-09-11 05:02
``` before => init server, add any external mocks needed, setup provider ``` Can you share the code that does this, please? Ideally from each test file

tjones
2019-09-11 05:03
Also, which test framework are you using?

robin
2019-09-11 08:06
Hi Tim, I?m using lab from the Hapi js suite. I?ll create a repo to share on github

robin
2019-09-11 08:34
Hey Tim. I?ve created a repo with my tests folder. It contains my entire test setup and some context (package.json, server file, etc.). I cannot add all the context obviously but I hope this helps!


matt.fellows
2019-09-11 13:04
Thanks Robin, this is really great. I'll take a look tomorrow (apologies was running a meetup tonight). I suspect the pact log will be illuminating in further understanding. My suspicion is that write pact might only need to be called once at end end of it all. But I'm looking on a mobile and may have missed something

matt.fellows
2019-09-11 13:05
Beautiful code, btw

robin
2019-09-11 13:12
Thanks Matt and thanks for your help. I?m still testing different options, I?ll keep you posted if I find anything :slightly_smiling_face:

robin
2019-09-11 13:27
I?ve also added the latest pact.log, which is a reflection of the pact json file and only logs the latests interactions

matt.fellows
2019-09-12 00:17
Thanks for that Robin. I?ve just pulled it down now, unfortunately a bunch of dependencies don?t seem to be downloadable and I can?t run it.

matt.fellows
2019-09-12 00:18
e.g. `npm ERR! 404 Not Found: @citizenplane/pygmalion@^1.0.3`

robin
2019-09-12 09:27
Ah, indeed, those are our internal modules

robin
2019-09-12 09:27
let me see what I can do

robin
2019-09-12 09:35
Okay I?ve changed the npm settings from private to public you should be able to pull it. However you won?t be able to run the tests without the codebase and I unfortunately can?t really share that with you

matt.fellows
2019-09-12 09:50
All good. I'll try to reproduce another way

robin
2019-09-12 14:14
Thanks, let me know if I can help

robin
2019-09-13 09:49
Morning everyone. I?m working now on my provider verification tests. Our API has a few models with null or typed field and arrays / object that can be either empty or filled with relational data. I?ve understood looking at the documentation that, for good reason, matchers do not allow these specific use cases and that I should rater use different states to specify my interactions. That?s not a problem and it works quite well. However, when it comes to provider verification, I?m a bit stuck. If I want to make sure that the data saved in the interactions will, in fact, match the data returned by the provider, I have to mock my database queries. If I?m running a seeded database I have no control over the data inside the database as it is randomized and thus I could have failed verification because a field is a string and not null, or an array is not empty, etc. I already mock database queries for my integration tests but I know exactly which query I need to mock and which data needs to be returned. When I?m running all the verifications, That?s a bit more complicated because I have potentially a lot of queries to mock. I also need to know the order if I want to do it right. And if there?s several consumer depending on my consumer, which interaction will get verified first? How do you usually make sure your provider database data will match the interactions saved if there are some optional fields and / or fields that can be either null / typed, etc.?

matt.fellows
2019-09-13 11:15
Morning!

matt.fellows
2019-09-13 11:15
(or in our case, evening!)

matt.fellows
2019-09-13 11:25
So basically, because consumers depend on these states, and provider builds can fail because of them, I usually do the following as the initiative progresses (if doing pure consumer-driven, for obvious reasons you won?t be able to do all of this): ? Advertise specific entities / scenarios that exist in advance for anyone to use (e.g. Users, Orders, whatever - useful for the `200` type scenarios) ? Create and agree on a standard convention for describing the ?states?. There is no one way of doing this, and it?s ideal there are fewer of them for the provider to have to worry about. This can be in a Wiki page, the providers? repository or some place that everyone has shared and immediate access to. I usually implement this via data fixtures and running a real database (e.g. in Docker), so I can control most things like IDs

robin
2019-09-13 12:11
Hum okay so, if I understand correctly: - You?re running a real database with a known set of data that you use during your provider tests - In order to do that, you share some specific entities with corresponding IDs for everyone to use when testing consumers and writing interactions - Which means that the data you?re using when writing your interaction has to match an entity in the database which will also match the state described in the interaction Is that right?

matt.fellows
2019-09-13 12:21
Yep. There are many ways to achieve that - the standard is probably that a consumer drafts a contract, with a state that makes sense for their use case, and before it becomes ?real? (e.g. tagged with ?master? or ?prod?) it might get reviewed and updated based on the provider teams? feedback

matt.fellows
2019-09-13 12:22
@uglyog thoughts / additions? I feel like we could probably publish more about our thinking on this, including how to describe the tests (BDD vs API description vs ..)

robin
2019-09-13 12:37
I see, thanks for the explanation, that?s an interesting process. In our current organization, I feel this is actually a bit overkill. We?re only 5 engineers with 10 - 15 microservices. We?ve only recently started thinking about our whole framework and that?s how I started working with Pact. Ideally I wanted to implement something along the line of: *For the consumer* - All external services are mocked with different state / scenarios to test API responses - Database queries are mocked as well - Internal services are mocked with Pact & interactions are registered using Joi schemas from the consumer to dynamically generate the payload & Joi schemas from the provider to dynamically generate the response (I?ve developed an internal module that generates a random data set based on a joi schema and another module holds all our validation schemas) *For the provider* - Same logic for integration tests - As for the pact verification tests, mocking database queries seem impossible for the reason I?ve written above. Therein lies the rub The reasoning behind this was to avoid hardcoding data inside the tests. I also didn?t want to have to manually type my payloads or update them every time I made a change to the validation schema. However, randomizing payloads means I?ve got to mock my database queries and that wouldn?t work on the provider side

abubics
2019-09-15 23:55
I use the same approach, in principle, but stub out the API way closer to the HTTP layer . . . usually cutting off around the use-case layer. It does mean I have to build fixtures up in every language/platform that needs them, though.

abubics
2019-09-15 23:56
Which potentially could be solved with a library of JSON fixtures, for example . . .

matt.fellows
2019-09-16 00:59
> However, randomizing payloads means I?ve got to mock my database queries and that wouldn?t work on the provider side Yes, the randomness is what will make this problematic. Pact JVM actually provides the facility to inject values through states (https://blog.pactflow.io/injecting-values-from-provider-states/: which would / could help with this) but I?d recommend against this for other reasons.

matt.fellows
2019-09-16 01:00
The main reason is that if you go down the manage your contracts and workflow through the Pact Broker path, you won?t be pre-verified (value changes in a contract that is otherwise structurally equivalent will be seen, at least for now, as a contract change, so you won?t get some of the benefits of the can-i-deploy tool https://docs.pact.io/pact_broker/can_i_deploy)

robin
2019-09-16 13:12
Hum missing pre-verification would indeed be a shame. And I?m not even sure how provider states could work vs a fully randomized interaction. Well, I?ll reevaluate my current setup, either keep with what I have and remove pact for now or change how I generate test data & mock the db and set up pact now. Thanks for your time and answer :slightly_smiling_face:

lauri.vaeaenaenen
2019-09-16 16:09
has joined #pact-js

kiranpatel11
2019-09-16 21:11
has joined #pact-js

matt.fellows
2019-09-16 21:29
You seem to be thinking about it right, so keep going and if you have more questions let us know

matt.fellows
2019-09-16 21:29
Btw, do you use OAS at all?

matt.fellows
2019-09-16 21:33
Also, we may eventually improve the prr verification checks to be content independent

robin
2019-09-17 08:00
No I don?t use OAS, I used to but I migrated to a self-hosted, markdown-based api documentation. It?s purely for documentation purposes though

dianaszaharia
2019-09-19 10:46
has joined #pact-js

lwillmeth
2019-09-19 19:07
has joined #pact-js

lwillmeth
2019-09-19 19:27
Hi @here, I'm new to pact-js and have a general question, let me know if there's a better channel? Should I be making many assertions in my consumer contract tests? I've seen this pattern in most of the pact example projects, but I'm not sure why. I realize setting up the provider mocks and calls are necessary to generate the contract, but AFAIK the real provider responses won't be compared against the consumer assertions. All that matters is if the data in the consumer contract matches the provider's responses, right? I could see comparing the provider mocks against my unit test mocks, but copying my unit test assertions into my contract tests seems like it's just adding maintenance overhead. I'd rather just replace some of my unit test mocks with provider mocks. Any thoughts or comments are welcome.

lwillmeth
2019-09-19 19:36
Maybe I should be adding pact interactions during my unit tests, instead of separating them as so many examples do.

matt.fellows
2019-09-20 02:15
> All that matters is if the data in the consumer contract matches the provider?s responses, right? Yes, or more specifically in most cases, just the shape of the data.

matt.fellows
2019-09-20 02:16
> Should I be making many assertions in my consumer contract tests? I?ve seen this pattern in most of the pact example projects Can you share an example as to what you think is the anti-pattern here? If we have bad examples we ought to fix them



matt.fellows
2019-09-20 02:18
but the short answer is that you want to be testing your collaborator companent, which may involve multiple assertions. If they overlap with unit tests, reduce the overlap to the smallest amount until you still catch any potential integration issue

tjones
2019-09-20 04:49
Are you asking why we need to assert on the response in the test?

tjones
2019-09-20 04:51
Oh, yeah, we have some anti-patterns in the examples

tjones
2019-09-20 04:51
in the jest examples, it says:

tjones
2019-09-20 04:51
``` it("returns a sucessful body", done => { return getMeDogs({ url, port, }) .then(response => { expect(response.headers["content-type"]).toEqual("application/json") expect(response.data).toEqual(EXPECTED_BODY) expect(response.status).toEqual(200) done() }) .then(() => provider.verify()) }) ```

tjones
2019-09-20 04:52
So, pact does the assertion of the response codes / headers etc for you

tjones
2019-09-20 04:52
However, in a clean design you'd expect the response from your API layer to be a domain object, rather than an http response object


tjones
2019-09-20 04:54
``` it('returns the number of times this score has been reached', done => { scoreBoard .reachedScore(12) .then(({ reachedBy, globalHighScore }) => { expect(reachedBy).toEqual(EXPECTED_BODY.timesReached); expect(globalHighScore).toEqual(EXPECTED_BODY.globalHighScore); }) .then(done); }); ```

tjones
2019-09-20 04:55
In javascript, it is often the case that your API layer just returns the body, so yes, your test often looks like:

tjones
2019-09-20 04:56
``` it('returns the body', () => callApi(someConfig).then(data => expect(data).toEqual(EXPECTED_BODY)); ) ```

tjones
2019-09-20 04:57
Pact ensures that the mock provider will return what you asked for (if the request is what you said it would be) Then your unit test needs to assert that your API call returned the domain object that you are expecting

tjones
2019-09-20 04:58
it's an anti-pattern to put the http call, or the http response in the pact test

tjones
2019-09-20 04:58
The best practice is to call the api wrapper (which will do the call)

tjones
2019-09-20 04:58
essentially, you're testing everything that you wouldn't unit test

tjones
2019-09-20 05:00
>Maybe I should be adding pact interactions during my unit tests, instead of separating them as so many examples do. This is more a practical point - pact tests take much longer to run than the rest of your unit tests. If you don't mind longer test runs, you can run pact as part of the rest of your test suite. I have done both, it depends on the project

tjones
2019-09-20 05:04
In english, a single pact test says: ? If I send this request (`withRequest`) ? I'll get this response from the server (`willRespondWith`) ? This happens when I call this function (whatever your function call is, inside a `test` or `it`, or whatever your test framework has - and `provider.verify()` confirms this) ? The calling code returns this object to the caller (this is the assertion)

tjones
2019-09-20 05:04
let me know if the explanation isn't clear

tjones
2019-09-20 05:06
Put simply: > All that matters is if the data in the consumer contract matches the provider's responses, right? No. It also matters that the calling code gets the right object returned. Otherwise an implementation like: ``` const apiCall = (someParams) => { axios.get(/* .... */); return 'something irrelevant'; } ``` might pass the tests.

lwillmeth
2019-09-20 17:12
Thanks for the detailed responses! I'll read up and continue learning from your links. I'm too new to Pact and contract testing to have an informed opinion on anti patterns yet. I see that broker validation may take quite awhile, which is a great argument for separating contract from unit tests. Thanks again for the responses, and your hard work on this project. I'm really looking forward to working with Pact.

tjones
2019-09-24 00:49
On this day one year ago, pact-js had around 6,000 weekly downloads on npm. Today it is 36,000

tjones
2019-09-24 00:50
You're welcome! Please let us know if you have any further questions.

matt.fellows
2019-09-24 01:40
According to our analytics, which I trust more than npm, it?s actually more like 80k

bernardo.guerreiro
2019-09-24 07:09
6 digits incoming !

uglyog
2019-09-25 23:15
@matt.fellows I have some capacity this weekend to work on the V3 beta. You did push up all the changes you did?

matt.fellows
2019-09-25 23:27
shit, no. It?s on the other laptop. Setting reminder in my phone now

angela.gloyna
2019-09-26 06:01
has joined #pact-js

vk.regs
2019-09-26 08:49
has joined #pact-js


bethskurrie
2019-09-28 07:59
FFS

matt.fellows
2019-09-28 11:19
That?s awesome news Ron. I?ll try to take a look tomorrow

catrionamcgarvey
2019-09-29 00:21
has joined #pact-js

reachbharathan
2019-10-03 13:09
has joined #pact-js

vitaliy.grigoruk
2019-10-08 14:56
Hi everybody. We would like to make provider verification job less verbose. Currently, for each request in pact contract (both passed and failed) we get something like this in STDOUT (I guess this is RSpec reporter used in pact-ruby): ``` Given [{"name":"token does not exist","params":{"token":"invalid"}}] invalid response token auth request with POST /v1/auth/token returns a response which has status code 422 has a matching body includes headers "Content-Type" which equals "application/json; charset=utf-8" ``` This is too verbose for my team... Developers complain that they?re lost in this huge output and they want to get an output for failed tests only. Any suggestions where I should look?

tjones
2019-10-08 22:00
I think you're correct about the reporter

tjones
2019-10-08 22:01
pact-js uses https://github.com/pact-foundation/pact-provider-verifier for the verification, which supports either custom formatting or redirecting the output

tjones
2019-10-08 22:04
However, specifying the format isn't exposed in the js wrapper


tjones
2019-10-08 22:05
How are you kicking off the verification?

bethskurrie
2019-10-08 22:08
It'll need to be added to the wrapper then.

tjones
2019-10-08 22:09
Oh hi! I just asked about this in #pact-ruby-standalone - I'm not sure what the option should be set to for this case

bethskurrie
2019-10-08 22:09
I'm not sure if the progress formatter is supported (that's the low noise one) but it easily can be.

tjones
2019-10-08 22:09
``` --format=FORMATTER # RSpec formatter. Defaults to custom Pact formatter. Other options are json and RspecJunitFormatter (which outputs xml). ```

bethskurrie
2019-10-08 22:10
Yeah, looks like the low noise one isn't supported yet. I think it's "progress".

bethskurrie
2019-10-08 22:10
@vitaliy.grigoruk you can run one interaction at a time, btw.

tjones
2019-10-08 22:10
Cool. Want me to open an issue against pact-provider-verifier?

tjones
2019-10-08 22:11
I can make a PR to expose the option in the wrapper

bethskurrie
2019-10-08 22:13
I've just tested it, and you can set --format progress and it will only show failures.

tjones
2019-10-08 22:14
sweet, I'll expose this in pact-node sometime today. Thanks!

bethskurrie
2019-10-08 22:15
np

matt.fellows
2019-10-08 22:17
Which test framework do you use, btw? E.g. Mocha, jest ...

tjones
2019-10-08 22:18
@vitaliy.grigoruk, I created https://github.com/pact-foundation/pact-node/issues/188 to track this

vitaliy.grigoruk
2019-10-09 07:28
we don?t use any frameworks at the moment. We have 1 js file which launches pact-provider-verifier via pact-js and that?s it.

matt.fellows
2019-10-09 07:42
If you were to use one, what would you use? The reason being, I'd like to be able to report each verification as a single item so you can get usual test reporter output instead of a single pass or fail for the whole thing

vitaliy.grigoruk
2019-10-09 07:46
I personally like jest, but we use mocha already in our provider codebase, so I?d love to have mocha

vitaliy.grigoruk
2019-10-09 11:47
could you please explain how I can do this with pact-js / pact-node?

bethskurrie
2019-10-10 20:28
It should be in the output of the failed test. If it's not then I'll raise an issue.

bethskurrie
2019-10-10 20:29
Set the env vars PACT_DESCRIPTION and PACT_PROVIDER_STATE to match the one you want

bethskurrie
2019-10-10 20:29
Though you're running a v3 pact with an array of states, so I'm not sure that the provider state will match.

bethskurrie
2019-10-10 20:30
Try just setting the description

vitaliy.grigoruk
2019-10-11 07:03
didn?t know about this feature. Thank you for sharing! Yes, we use v3 provider states encoded into a string (so it is v2 compatible). I?ll check if I see this in the output, if not - I?ll create a ticket

lwillmeth
2019-10-16 17:04
I see that I can pass the Verifier either filenames via `pactUrls`, or fetch pacts from a broker via `pactBrokerUrl`, but can I pass it JSON instead? I could write the JSON to disk and pass the verifier temporary filenames, but would rather avoid that.

joshwakefield45
2019-10-16 18:13
has joined #pact-js

matt.fellows
2019-10-16 20:34
It doesn't accept inline json at the moment. Can you elaborate why you might need it?

lwillmeth
2019-10-16 20:37
I'd like to use a custom pact broker to get better control over which pacts should be verified. That means I need to either fetch the pacts and write them to disk, or figure out a way to replace the default Verifier request with my own.

lwillmeth
2019-10-16 20:39
The simplest workaround seems to be having the provider fetch and write pacts to disk, then passing the filenames to the Verifier via pactUrls.

matt.fellows
2019-10-17 07:05
Yep, writing to disk is by far the easiest

matt.fellows
2019-10-17 07:05
What's missing in the broker that we should add for your use case?

thakkarjinal29
2019-10-17 11:52
Hello, I am writing consumer tests for our angular application, in which for 1 of the API we send the request body as `multipart/form-data`. The mock service is giving this error `Error ocurred in mock service: NoMethodError - undefined method 'encoding' for #<Hash:0x007f898a108d38>`. I came across a similar issue https://github.com/pact-foundation/pact-support/issues/68 which was I think fixed about a month or more ago. I have the latest `pact-node` and `pact-web` packages which use the standalone version `darwin-1.70.2`. But it does not seem to work for me. Could someone help please.

lwillmeth
2019-10-17 16:24
We have some legacy providers that are not versioned, so I'm tapping into our CI/CD pipeline to archive old contracts when those providers update. (I'm also pushing to add versions, but that's been surprisingly controversial.) I'm storing the contract objects in the same format, and would use the default Verifier request to fetch them, but my broker is implemented in graphql, so it would mean modifying the request. I appreciate all of your work on this project, we're pretty excited to add contract testing via Pact.

thakkarjinal29
2019-10-18 05:48
Hey @bethskurrie @matt.fellows, could you guys take a look please?

bethskurrie
2019-10-18 06:16
@thakkarjinal29 can you see the instructions I gave that user to recreate the issue? Can you please do the same?

bethskurrie
2019-10-18 06:16
Also, check that you're setting your content type and accept headers correctly.

thakkarjinal29
2019-10-18 06:17
Yes, will do it thanks!

travis.anderson
2019-10-18 18:02
has joined #pact-js

stevi.deter
2019-10-21 20:27
has joined #pact-js

travis.anderson
2019-10-21 22:18
Screenshot of a discussion I was having on the pactteshelp channel. I didn't realize there was nobody from Pact on the channel. Can anyone provide some insight on this to help me understand how Provider verification actually works?

matt.fellows
2019-10-21 22:33
Sorry, I didn?t know what the channel was or why it existed. We all tend to hang out in the language specific channels

matt.fellows
2019-10-21 22:34
I?ve answered the first bit

travis.anderson
2019-10-21 22:46
No worries, I have found it. Working on processing all of the answers :slightly_smiling_face:

lwillmeth
2019-10-21 23:16
Is anyone here familiar with Pact's `GraphQLInteraction`? I'm having an issue where my consumer query does not match the expected query, because regex sees unexpected newlines and `__typename`. I'm using the same gql string for both queries, and I tried formatting it on one line, but apparently `apollo-boost` reformats it onto multiple lines.

matt.fellows
2019-10-21 23:17
hmmm

matt.fellows
2019-10-21 23:17
I think there is an open issue at the moment on the repo, maybe double check that you?re not running into that

lwillmeth
2019-10-21 23:17
Here's the diff: ``` Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "body": { - "query": /query\s*QueryContractById\(\s*\$provider:\s*String!\s*\$contractId:\s*ID!\s*\)\s*\{\s*contractById\s*\(\s*provider:\s*\$provider\s*contractId:\s*\$contractId\s*\)\s*\{\s*contractId\s*provider\s*consumer\s*\}\}/ + "query": "query QueryContractById($provider: String!, $contractId: ID!) {\n contractById(provider: $provider, contractId: $contractId) {\n contractId\n provider\n consumer\n __typename\n }\n}\n" } } ```

matt.fellows
2019-10-21 23:18
can you not add `__typename` into the expected query?

lwillmeth
2019-10-21 23:19
I'll do that and try some suggestions from the github issue here: https://github.com/pact-foundation/pact-js/issues/292

matt.fellows
2019-10-21 23:20
thx, let us know how you go

matt.fellows
2019-10-21 23:20
happy to evolve that API as I know it?s not perfect

abubics
2019-10-21 23:27
Whoa, yeah, never heard of that channel :sweat_smile:

lwillmeth
2019-10-22 00:00
It looks like apollo-boost changes the string by adding commas, which don't match the Pact regex. I finessed my `withQuery` string to match what Pact expects and got it working for now, but making commas optional would be better. Thanks for your prompt response earlier, and have a great rest of your day!

lwillmeth
2019-10-22 00:02
The newlines threw me off for a bit because they fail regex testers, but don't seem to fail the actual comparison. So there may be something fishy there.

lwillmeth
2019-10-22 17:00
Setting up some new interactions with Mocha and ApolloGraphQLInteraction. Both interactions pass separately, but when run together the second interaction fails: `No matching interaction found for POST /graphql` The docs say I should call `provider.verify()` after every test, but this seems to cause a problem. Calling it once at the end passes, and seems to exercise all of the interactions, because my responses include data from the mocks. Any thoughts or advice?

matt.fellows
2019-10-22 20:32
Can you share your test, or an outline of it?

lwillmeth
2019-10-22 20:40
Here's an example: https://gist.github.com/lwillmeth/9fb7163fd729cd22e95985bbad79c6df It passes as written, but using provider.verify after each test INSTEAD of once at the end, causes the second test to fail.

lwillmeth
2019-10-22 20:42
My understanding is that calling provider.verify deletes any outstanding interactions, so it's better to add and verify them one at a time?

lwillmeth
2019-10-22 20:43
So the suggested pattern is addInteraction, call API, verify?

matt.fellows
2019-10-22 21:02
The working pattern is how we do the examples in Pact JS repo, did you see something to the contrary?

matt.fellows
2019-10-22 21:03
But yes, you need to verify per test (`it`) block for the reasons you describe

matt.fellows
2019-10-22 21:04
If a test needs two interactions it it, that's totally fine too, as long as your test cases hits both interactions

lwillmeth
2019-10-22 21:11
ah, I found the problem. Because I was running the mocha blocks async, the first verify was running after the second addInteraction had been called. So the first verify was wiping out the second interaction before it was being used. Thanks for the quick response, have a great rest of your day!

matt.fellows
2019-10-22 21:17
ah cool, no worries

matt.fellows
2019-10-22 21:17
:thumbsup:

matt.fellows
2019-10-22 23:28
Thanks Levi. What I would have preferred to do with the library, was convert any gql query to an intermediate AST, and then serialise that to JSON which could be matched by the underlying library. There are barriers to doing that in a cross-language way, so a regex comparison was the simplest/crudest way to achieve it. I?ll think about how the above case could be done. Thanks for your feedback though

yosevuk
2019-10-24 14:16
has joined #pact-js

yosevuk
2019-10-24 14:21
Hello! Can I use the `pactUrls` verification option to list the pact urls from different brokers?

vitaliy.grigoruk
2019-10-24 14:29
why do you have 2 brokers?

yosevuk
2019-10-24 14:35
Well, we are switching to a new one, but it is gradual and there are active contracts on the old one. For example, Providers might have consumers that are using either the old or new broker and want to verify contracts from both. (I think the best answer is to just use one and have teams update, but not always straightforward or timely to coordinate)

yosevuk
2019-10-24 15:34
I think another option is to use two different publish scripts.

matt.fellows
2019-10-24 22:31
I don't think you can

matt.fellows
2019-10-24 22:32
I would just run the verification process twice with the same options, except with different broker URLs provided. It has the same net effect

yosevuk
2019-10-25 20:21
Thanks, that's what I did :smile:

bethskurrie
2019-10-25 22:18
@yosevuk you could, except that the auth credentials can only be specified once.

yosevuk
2019-10-26 00:57
Got it, makes sense Beth!

brandontylerwilliams
2019-10-27 20:34
has joined #pact-js

brandontylerwilliams
2019-10-27 20:34
~

tjones
2019-10-28 05:51
Does anyone @here use pact-node or pact-js on windows, and would be able to help me beta test a change?

tjones
2019-10-28 05:52
I've changed the way that arguments are passed to the binaries, and want to double confirm that it still works on windows before releasing (tests still pass in appveyor, but I'd like to try a real machine too before committing to a release)

yousafn
2019-10-28 14:06
happy to test out the fix @tjones we have quite a few staff at ours trying to use jest-pact on windows with a combination of either WSL, Vagrant or plain windows and coming across issues

srinivasan.anusha
2019-10-28 22:51
has joined #pact-js

archana.rachuri
2019-10-31 02:45
has joined #pact-js

sarajcarbajal
2019-10-31 16:49
has joined #pact-js

james.hattersley-dyke
2019-11-04 10:17
Hi, does anyone know of a way around this error using pact-js & jest. ``` $ cross-env && jest --testRegex "./tests/pact/.*/*(.test.pact.js)" --runInBand --setupFiles ./tests/pact/pactSetup.js --setupTestFrameworkScriptFile=./tests/pact/pactTestWrapper.js [2019-11-04T10:13:02.319Z] INFO: pact-node@10.0.1/581 on ip-10-64-52-241.eu-west-1.compute.internal: Creating Pact Server with options: {"consumer":"fe-fragment-user-insight","cors":false,"dir":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/pacts","host":"127.0.0.1","log":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8080,"provider":"user-insight","spec":2,"ssl":false} [39mFAIL tests/pact/user-insights/mandatory-fields.test.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 9 | 10 | afterAll(done => { > 11 | return provider.finalize().then(() => done()) | ^ 12 | }) 13 | at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.finalize (tests/pact/pactTestWrapper.js:11:19) ``` it's pretty much copying the jest example verbatim in terms of pactSetup.js and pactTestWrapper.js etc etc

james.hattersley-dyke
2019-11-04 10:18
works fine on a Windows machine, for development, fails on CI. Was previously working fine.

james.hattersley-dyke
2019-11-04 10:23
I saw the github issue was closed with the solution to update the timeout, I've tried that and it's not been successful. Any other advice would be greatly received.

matt.fellows
2019-11-04 11:14
hmm that?s a worry. I haven?t had the capacity the last week but Tim has been doing a great job of going through these

matt.fellows
2019-11-04 11:15
Can you check if you can run the underlying mock service directly?

matt.fellows
2019-11-04 11:15
`./node_modules/.bin/pact-mock-service`

matt.fellows
2019-11-04 11:16
`DEBUG` mode doesn?t give you anything more either?

james.hattersley-dyke
2019-11-04 11:18
trying to start the mock server manually yields: ```$ cross-env chmod +x ./debug-pact.sh && ./debug-pact.sh INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] WARN TCPServer Error: Cannot assign requested address - bind(2) for "::1" port 33249 INFO WEBrick::HTTPServer#start: pid=595 port=33249 ```

james.hattersley-dyke
2019-11-04 11:18
just gonna try with debug mode on

matt.fellows
2019-11-04 12:50
Interesting. Looks like IPv6 interface isn't available. I wonder if you're running into that issue (see open issues, we're working thru that now. Seems unlikely tho)

james.hattersley-dyke
2019-11-04 14:24
@mr.matt.r.long closest issue is this one, that i can find https://github.com/pact-foundation/pact-js/issues/383

matt.fellows
2019-11-04 21:57
That's the one

matt.fellows
2019-11-04 22:00
Same symptoms?

james.hattersley-dyke
2019-11-05 09:39
yep

james.hattersley-dyke
2019-11-05 09:39
I'm rolling back to an earlier version that worked on CI to see how I get on.

james.hattersley-dyke
2019-11-05 09:39
same test code etc

james.hattersley-dyke
2019-11-05 09:43
I rolled back to ``` pact@9.1.1 pact-node@9.0.4 ```

james.hattersley-dyke
2019-11-05 09:58
and it worked!

matt.fellows
2019-11-05 10:02
Thanks James. I hope to get to look into this tomorrow, appreciate this feedback

james.hattersley-dyke
2019-11-05 10:10
:+1:

james.hattersley-dyke
2019-11-05 14:44
As an aside, this was the last step into getting a fully fledge pact workflow set up. I've got tagging, webhooks and provider verification builds all set up!

bernardoguerr
2019-11-05 20:21
has joined #pact-js

matt.fellows
2019-11-05 22:04
WOOT!


paras.vora
2019-11-08 07:43
Cant the name of variable `provider` be any other name, say as below: ```global.myprovider = new Pact({ port: global.port, log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "pacts"), spec: 2, pactfileWriteMode: "update", consumer: "MyConsumer", provider: "MyProvider", })```

matt.fellows
2019-11-08 07:45
Yes, why couldn't it?

matt.fellows
2019-11-08 07:45
The variable name has nothing to do with Pact

paras.vora
2019-11-08 07:45
``` Creating Pact Server with options: consumer = ipa-itg, cors = true, dir = /Users/parasvora/workspace/ipa-itg/pacts, host = 0.0.0.0, log = /Users/parasvora/workspace/ipa-itg/logs/mockserver-integration-provider-itg-composition.log, pactFileWriteMode = merge, port = 8092, provider = itg-composition, spec = 2, ssl = false, sslcert = , sslkey = FAIL tests/__contract_tests__/__tests__/pact-provider-itg-composition.tests.js ? Test suite failed to run ReferenceError: provider is not defined 3 | 4 | beforeAll(() => provider.setup()); > 5 | afterAll(() => provider.finalize()); | ^ 6 | afterEach(() => provider.verify()); 7 | at Object.<anonymous> (tests/__contract_tests__/pact-test-wrapper.js:5:10) ```

paras.vora
2019-11-08 07:46
I am getting this error when I am using this: ``` global.provider_itg_composition = new Pact({ port: global.port_provider_itg_composition, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration-provider-itg-composition.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, logLevel: 'INFO', pactfileWriteMode: 'merge', consumer: 'ipa-itg', provider: 'itg-composition', host: '0.0.0.0' }); ```

matt.fellows
2019-11-08 07:46
If you rename the variable in the wrapper you need to rename it in your test also

paras.vora
2019-11-08 07:47
``` const axios = require('axios/index'); const port = global.port_provider_itg_composition; describe('ipa-itg consumer tests', () => { const URL = 'http://127.0.0.1'; describe('Preview PDF section', () => { const ENDPOINT = '/api/v1/invoices/templates/APPDIRECT_DEFAULT_TEMPLATE_EN_US/versions/APPDIRECT_DEFAULT_TEMPLATE_VERSION_EN_US/pdf'; beforeEach(() => { const interaction = { state: 'i need to preview PDF in pdf preview section', uponReceiving: 'a request to preview pdf', withRequest: { method: 'GET', path: ENDPOINT, query: 'dataSource=PLACEHOLDER&clientId=APPDIRECT&scope=PARTNER', headers: { 'Content-Type': 'application/json', 'AD-Tenant': 'APPDIRECT' } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/pdf' } } }; return provider_itg_composition.addInteraction(interaction); }); it('Preview PDF section', done => { axios({ method: 'get', url: `${URL}:${port}${ENDPOINT}?dataSource=PLACEHOLDER&clientId=APPDIRECT&scope=PARTNER`, headers: { 'Content-type': 'application/json', 'AD-Tenant': 'APPDIRECT', Accept: 'application/json' }, data: null }).then(response => { expect(response.headers['content-type']).toEqual('application/pdf'); expect(response.status).toEqual(200); done(); }); }); }); }); ```

paras.vora
2019-11-08 07:48
``` Ran all test suites. console.error node_modules/jest-cli/node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Error: connect ECONNREFUSED 127.0.0.1:8092 at Object.dispatchError (/Users/parasvora/workspace/ipa-itg/node_modules/jest-cli/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19) at EventEmitter.<anonymous> (/Users/parasvora/workspace/ipa-itg/node_modules/jest-cli/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:676:20) at EventEmitter.emit (events.js:214:15) at Request.<anonymous> (/Users/parasvora/workspace/ipa-itg/node_modules/jest-cli/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:412:47) at Request.emit (events.js:209:13) at Request.onRequestError (/Users/parasvora/workspace/ipa-itg/node_modules/request/request.js:877:8) at ClientRequest.emit (events.js:209:13) at Socket.socketErrorListener (_http_client.js:406:9) at Socket.emit (events.js:209:13) at emitErrorNT (internal/streams/destroy.js:91:8) undefined ```

matt.fellows
2019-11-08 07:48
There must be another reference to it somewhere

matt.fellows
2019-11-08 07:48
If you borrow it from the example code I think there is a helper JavaScript file also

paras.vora
2019-11-08 07:48
``` const path = require('path') const Pact = require('@pact-foundation/pact').Pact; global.port_provider_itg = 8091; process.env.API_URL = `http://localhost:${global.port}`; global.provider_itg = new Pact({ port: global.port_provider_itg, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration-provider-itg.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, logLevel: 'INFO', pactfileWriteMode: 'merge', consumer: 'ipa-itg', provider: 'itg', host: '0.0.0.0' }); global.port_provider_itg_composition = 8092; global.provider_itg_composition = new Pact({ port: global.port_provider_itg_composition, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration-provider-itg-composition.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, logLevel: 'INFO', pactfileWriteMode: 'merge', consumer: 'ipa-itg', provider: 'itg-composition', host: '0.0.0.0' }); ```

paras.vora
2019-11-08 07:48
My pact setup :point_up_2:

matt.fellows
2019-11-08 07:50
The error you showed is related to the code that is called in the before all and after all blocks. find those

matt.fellows
2019-11-08 07:50
There is still a dangling reference to provider somewhere

paras.vora
2019-11-08 07:50
:thinking_face: let me check

paras.vora
2019-11-08 07:55
@matt.fellows Got it, thanks.

paras.vora
2019-11-08 07:55
` Pact Binary Error: Could not load existing consumer contract from /Users/parasvora/workspace/ipa-itg/pacts/ipa-itg-itg-composition.json due to 757: unexpected token at 'null'. Creating a new file.`

paras.vora
2019-11-08 07:55
any idea on this :point_up_2:

matt.fellows
2019-11-08 08:54
It sounds like the json file is corrupt or invalid?

matt.fellows
2019-11-08 08:54
Was it manually modified?

iammrrhodes
2019-11-08 11:31
has joined #pact-js

iammrrhodes
2019-11-08 19:26
Hey everyone, I'm trying to use that `providerVersionTag` property that was just added and i get this error.. ``` Error reading file from --provider-version-tag No such file or directory @ rb_sysopen - --provider-version-tag /builds/............/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.70.2/lib/vendor/ruby/2.2.0/gems/pact-support-1.11.0/lib/pact/consumer_contract/pact_file.rb:51:in `read' ```

matt.fellows
2019-11-08 22:14
OK I?m on it

matt.fellows
2019-11-08 22:19
looks like that flag isn?t available in the current pact-node

matt.fellows
2019-11-11 00:14
we have a new feature available to Pact JS to remove the pain point of consumers breaking a provider build with new / changed contracts. If you?d like to opt-in to a beta of this, please DM me.

paras.vora
2019-11-11 04:14
No, it wasn't.

matt.fellows
2019-11-11 04:16
Are you able to share that file? Something must be wrong if it can?t be read

matt.fellows
2019-11-11 04:17
OK, googling that error seems that there might be an array matcher with `null` in it


matt.fellows
2019-11-11 04:17
Anything you can share will help



matt.fellows
2019-11-11 09:50
Thanks. Wondering if it?s even an issue? Maybe the file doesn?t exist in the first place so it creates it?

matt.fellows
2019-11-11 09:50
What does the JSON look like before running the tests?

matt.fellows
2019-11-11 09:50
Oh - just double check that you?re not running tests in parallel - that could mean multiple processes writing to the same file at once

kv
2019-11-11 13:48
has joined #pact-js

roman.g.rodriguez
2019-11-12 12:38
has joined #pact-js

roman.g.rodriguez
2019-11-12 12:48
Hello All! I?d like to know what do you think about two approaches about pact files naming. Context: React app + graphql. Some components folders could contain more than one gql query file inside *Approach 1:* To have only one pact test file with the name `test.pact.js`, just one file with all interactions on it *Approach 2:* To have one pact test file per query file following the name of the query it checks wich do you think is better and why? I?d choose the second one because if you need to move the query to another component folder it would be easier by moving files together, but I see some projects using the first one

ncritah
2019-11-19 20:44
has joined #pact-js

ncritah
2019-11-19 20:45
Trying to use pact with Karma and Mocha but without much success. I have updated my karma conf to match the example shown and the rest of my code is as shown below ```*====client.js====* const validate = (host) => { const { url, port } = host; return axios .request({ method: 'GET', baseURL: `${url}:${port}`, url: `/test/111`, headers: { Accept: 'application/json' }, }); }; *====test.js====* describe('Pacting away', () => { let provider; const port = 1331; before(done => { provider = new PactWeb({ consumer: 'KarmaMochaConsumer', provider: 'KarmaMochaProvider', port: port, host: 'http://localhost', }); setTimeout(done, 1000); provider.removeInteractions(); }); after(done => provider.finalize().then(() => done())); describe('', () => { before(done => { provider .addInteraction({ state: 'provider can validate entries', uponReceiving: 'a request to validate 111', withRequest: { method: 'GET', path: '/test/111', headers: { 'Content-Type': 'application/json', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: { message:"Success" }, }, }) .then(() => { done(); }); }); it('should return 200 for 111', done => { validate({url: 'http://localhost', port: port}).then(response => { expect(response.status).to.equal(200); done(); }, done); }); }); });``` When I run the tests, it hangs after this log > `INFO [pact]: Pact Mock Server running on port: 1331` and when I manually try to access the endpoint in my terminal using curl, I get `{"message":"No interaction found for GET /test/111","interaction_diffs":[]}`

ncritah
2019-11-19 20:47
This is a repost of the earlier message I'd posted in general. Didn't realize we needed to post in the language-specific channels :see_no_evil:

sankalan13
2019-11-20 07:06
@ncritah Try removing the host from provider = new PactWeb. Let pact pick up the mock server url on its own.

sankalan13
2019-11-20 07:50
Hey @matt.fellows I am using Pact with Jest and Jasmine. Here is my pact test file: ```const accountService = require('../../repository/services/account-service'); const container = require('../../di'); const Pact = require('@pact-foundation/pact').Pact; const path = require('path'); jest.mock('../../drivers/spanner', () => require('../mocks/spanner.mock')); jest.mock('request'); jest.setTimeout(30000); // global.port = 1234; const provider = new Pact({ consumer: 'UserService', provider: 'AccountService', port: 1234, log: path.resolve(__dirname, '../logs', 'expectation-integration.log'), logLevel: 'TRACE', dir: path.resolve(__dirname, '../pacts'), pactfileWriteMode: "update", // host: '127.0.0.1', spec: 2, }); describe('User Service interaction with Account Service', () => { const ONE_ACCOUNT_BODY = { "userId": "6796fc82-ebac-4afd-8498-a963e7cf8fdf" }; const ONE_ACCOUNT_DETAILS = { "phoneNo": 919455334525, "countryAreaCode": 91 }; let temp = new accountService(container); // let config = container.resolve('config'); beforeAll((done) => { provider.setup().then(function () { console.log('Inside afterall'); done(); }, function (err) { done.fail(err); }); }); afterAll((done) => { provider.finalize() .then(function () { console.log('Inside afterall'); done(); }, function (err) { done.fail(err); }); }); afterEach((done) => { provider.verify().then(done, e => done.fail(e)); console.log('Inside aftereach'); }); describe('GET Interaction for getAccountData', () => { beforeAll((done) => { provider.addInteraction({ state: 'it has one user', uponReceiving: 'a request to retrieve user account data', withRequest: { method: 'GET', path: '/v1.0.0/getAccountInfo', headers: { 'Content-Type': 'application/json', 'cache-control': 'no-cache' }, body: ONE_ACCOUNT_BODY }, willRespondWith: { status: 200, body: ONE_ACCOUNT_DETAILS } }).then(() => { console.log('Inside 1 then'); done(); }, (err) => { console.log('Inside 1 error'); done.fail(err); }); }); it('should return a successful body.', () => { temp.getAccountData('6796fc82-ebac-4afd-8498-a963e7cf8fdf').then((response) => { expect(response.headers["content-type"]).toEqual("application/json"); expect(response.status).toEqual(200); expect(response.data).toEqual(ONE_ACCOUNT_BODY); }); }); }); });``` This is the function I am testing: ```getAccountData(userId) { return new Promise((resolve, reject) => { if (!userId) { return reject(`Invalid param ${userId}`); } const options = { url: `${this.config.services["xxxxxxxx"]}/v1.0.0/getAccountInfo`, method: 'GET', json: { userId: userId } }; console.log(options); request(options, (err, resp, body) => { if (err) { return reject(err); } if (resp.statusCode !== 200) { return reject({ code: resp.statusCode, msg: body }); } console.log(body); return resolve(body); }); }); }``` and here is my config services:

sankalan13
2019-11-20 07:50
```{ "services": { "bharat11-gaming-service": "http://localhost:3002/gaming-service", "bharat11-account-service": "http://localhost:3000/account-service", "bharat11-payment-service": "http://localhost:3003/payment-service" }, "db": { "instance": "bharat11-staging", "database": "bharat11-staging" }, "projectId": "bharat11-staging", "retailer": { "type": "retail" } }``` I am getting the following error: ``` FAIL test/services/account.service.test.js ? Console console.log test/services/account.service.test.js:41 Inside afterall console.log test/services/account.service.test.js:83 Inside 1 then console.log repository/services/account-service.js:73 { url: 'http://localhost:3000/account-service/v1.0.0/getAccountInfo', method: 'GET', json: { userId: '6796fc82-ebac-4afd-8498-a963e7cf8fdf' } } console.log test/services/account.service.test.js:60 Inside aftereach console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /v1.0.0/getAccountInfo See /Users/SankalanParajuli/repos/bharat11-user-service/test/logs/expectation-integration.log for details. console.log test/services/account.service.test.js:51 Inside afterall ? User Service interaction with Account Service ? GET Interaction for getAccountData ? should return a successful body. connect ECONNREFUSED 127.0.0.1:3000``` You can see in the console that the url reaching account service is the url defined in my config services. I am changing that url to where my pact mock server is running and still I am getting the same error that says missing requests. I am stuck in this from two days. Please help!

sankalan13
2019-11-20 07:53
If I use jest.mock('requests'), the connection refused error goes away. But I still can't get my getAccountData function to hit the pact mock server. I had done the same implementation using Karma and there I had used proxies to define where my URLs should be pointing. Can't find anything similar in jest.

sankalan13
2019-11-20 08:25
Is there a way I can map proxies in requests which I am mocking?

ncritah
2019-11-20 08:39
Still facing the same problem. I don't know whether I'm handling the promises wrong some how

bethskurrie
2019-11-20 09:25
@sankalan13 you'll get better help if you turn this into an executable example in a gut repository to share.

bethskurrie
2019-11-20 09:25
Pasting big slabs of code doesn't make it very easy for people to help you.

matt.fellows
2019-11-20 09:27
For starters, the pact mock sever is running on port 1234 but your test seems to hit port 3000.

sankalan13
2019-11-20 09:28
Yeah I changed it to hit 1234 in my config but getting the same error

sankalan13
2019-11-20 09:28
@bethskurrie thank you, I understand. I will push this to a git repository and share the link.

sankalan13
2019-11-20 09:28
Sorry for spamming the channel guys

sankalan13
2019-11-20 09:30
@matt.fellows is there a way I can proxy my requests like how we can do it in karma-pact using jest. I am mocking the request package but it still does not hit my mock server

matt.fellows
2019-11-20 11:42
I think for the `host` property simply `localhost` should suffice (the protocol isn?t needed). There are also a few minor JS things you could tidy up (e.g. remove the use of `done` in favour of returning Promises, and inlining certain things). This would simplify your test code

matt.fellows
2019-11-20 11:46
I?m not sure what you?re asking sorry, it sounds very much specific to your application

matt.fellows
2019-11-20 11:47
if you mock the requests library, that would make sense why the connection refused goes away - I?m assuming that would prevent it from making an HTTP call in the first place

matt.fellows
2019-11-20 11:47
It seems like something in your test setup is not rewiring your config to `http://ocalhost:1234`

ncritah
2019-11-20 20:50
Finally got it work :slightly_smiling_face:

ncritah
2019-11-20 20:53
Hi, So I am new to pact so pardon my kinda amateur questions. Just seen here that I can add multiple interactions to a provider here. > https://github.com/pact-foundation/pact-js. How do I do that? Do I have to do `provider.addInteraction` for each?

matt.fellows
2019-11-20 21:08
Do you need multiple interactions for a given test case (e.g. a scenario), or multiple interactions generally speaking? In both cases you need to call that method, and then you call the `verify` method after each test case to ensure your code did indeed make the call to the mock provider

matt.fellows
2019-11-20 21:09
What did it in the end?

ncritah
2019-11-20 21:31
multiple interactions when a particular endpoint is accessed with a certain id eg a 200 status for valid values, 404 for unknown ones etc

ncritah
2019-11-20 21:32
And from the documentation, the addInteraction is done in a the before method for the describe and I dont want to have each of these cases in its own describe block

matt.fellows
2019-11-20 21:43
They don't need to be in their own describe block. You can organise them however you want, so long as you call `verify` after your scenario runs.

matt.fellows
2019-11-20 21:44
As a general rule, each `it` block should be for a single scenario e.g. GET /product/:id You can do the `addInteraction` call in the same block if it makes sense and is cleaner, and then call `verify` after that

ncritah
2019-11-20 21:53
Looks much cleaner in the it block. Thanks for your help

matt.fellows
2019-11-20 21:55
With async/await I think there's a case for putting it all in the it block

ncritah
2019-11-20 22:19
yes, thats exactly what I have done. Works like a charm :slightly_smiling_face:

sankalan13
2019-11-21 05:55
I figured it out. I was mocking npm requests package using jest and Pact was mocking it too using the mock server so the jest mock was being called in place of the pact mock.

sankalan13
2019-11-21 07:12
Hi guys Does the npm @pact-foundation/pact have pact-node also in it now? Or do I have to independently install @pact-foundation/pact-node? Asking for using the publishPact functionality.

matt.fellows
2019-11-21 07:13
Yes

matt.fellows
2019-11-21 07:13
It should be there

matt.fellows
2019-11-21 07:13
It's an explicit dependency

sankalan13
2019-11-21 07:14
Thanks Matt!

matt.fellows
2019-11-21 07:15
:+1:

sankalan13
2019-11-21 10:49
I haven't been able to make it work with async await, is there a sample code anywhere with async await implementation?

matt.fellows
2019-11-21 11:09
There's nothing pact specific with async/await. Just replace any use of a promise with the new way instead

ncritah
2019-11-25 13:57
It was timing out. Needed to add the mocha property to my pact.json. Also took into consideration the tips you shared earlier. I will repost a working version here soon.

ncritah
2019-11-25 13:58
Used it for a client's project and haven't had a time to rewrite it to a working example


akiro
2019-11-25 14:49
has joined #pact-js

ambergkim
2019-11-26 05:27
has joined #pact-js

ncritah
2019-11-26 08:30
Hey, Just curious, is there any way to use pact with ES6 modules without using babel?

me1352
2019-11-26 13:02
has joined #pact-js

ben.quinteros
2019-11-26 22:37
has joined #pact-js

matt.fellows
2019-11-26 23:18
I think the question is really ?can I use ES6 modules without using babel?

matt.fellows
2019-11-26 23:22
Using Pact doesn?t require Babel or any transpiler, but if you want to use modern ES6 syntax you?re going to need something like that

matt.fellows
2019-11-26 23:25
There is experimental support in node v12, though, if that?s all you need

me1352
2019-11-27 07:36
I am working on the same issue: trying to use PactWeb without Babel in an ES6 only project. The setup is using Karma and at the moment it seems like PactWeb is not declared as a `module` and is not compatible with ES6 modules. At least this is how far I got. I am using `node v12.13.1` and `pact-web v8.2.6`.

matt.fellows
2019-11-27 09:56
I see what you mean. Can you please raise an issue and we can ensure the module package flag is added (and anything else it needs)?

me1352
2019-11-27 11:06
Sure Matt, thanks for your reply :slightly_smiling_face:

matt.fellows
2019-11-27 11:14
:+1:

paul.simms
2019-12-04 16:12
has joined #pact-js

matt.fellows
2019-12-09 01:27
@sankalan13 :point_up: want to take a look?

gordo
2019-12-09 22:27
has joined #pact-js

theriaultnicolas
2019-12-12 03:26
has joined #pact-js



mmonson
2019-12-18 23:18
Does pact-js have support for react hooks? Has anyone created a contract with react hooks?

matt.fellows
2019-12-18 23:19
I think if hooks are involved you?re probably doing something wrong. What?s the use case?

bethskurrie
2019-12-18 23:19
You took the words out of my mouth Matt!

matt.fellows
2019-12-18 23:19
_we?ve been working together for too long_

bethskurrie
2019-12-18 23:20
It's time we automated our responses :stuck_out_tongue:

bethskurrie
2019-12-18 23:20
Sorry Mark!

mmonson
2019-12-18 23:21
we have an axios call that's embedded in the useEffect of a react hook.

abubics
2019-12-18 23:26
My usual pattern (and recommendation) is to centralise calls like that into an API client :slightly_smiling_face: helpful for separation of concerns, and testability :ok_hand:

matt.fellows
2019-12-18 23:27
:point_up:

matt.fellows
2019-12-18 23:27
do this


matt.fellows
2019-12-18 23:27
or something like it. At least, refactor so that you can?t test things independently

zoeabryant
2019-12-19 10:47
has joined #pact-js

zoeabryant
2019-12-19 10:49
I'm having a problem where pact is not sending the body for a POST query when verifying the provider. The body is described in the pact contract, so I'm not sure what's going on

zoeabryant
2019-12-19 10:49
does anyone have a working graphql (as a provider) example I can look at? or tips for debugging?

matt.fellows
2019-12-19 11:36
Can you share the contract / test with us?

zoeabryant
2019-12-19 11:41
@matt.fellows shared contract ^

zoeabryant
2019-12-19 11:45
after some digging, I think my provider has been suppressing error messages :woman-facepalming: Hopefully that's what's causing the problem instead!

zoeabryant
2019-12-19 11:57
that's definitely it. Thanks anyway @matt.fellows!

matt.fellows
2019-12-19 12:40
haha :ok_hand:

matt.fellows
2019-12-19 12:40
no problems

mui_ume
2019-12-20 01:22
I?m looking for the implementation of provider pact test Is this the example that I should be looking at ? https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/provider.spec.js

mui_ume
2019-12-20 02:31
Can I have a simple example on how to setup the pact provider ? I am confused with the example given

mui_ume
2019-12-20 02:41
This is my publisher.js let publisher = require("@pact-foundation/pact-node") let path = require("path") let opts = { providerBaseUrl: "http://localhost:8082", pactFilesOrDirs: [path.resolve(process.cwd(), "pacts")], pactBroker: "https://test.pact.dius.com.au/", pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, consumerVersion: "2.0.0", } publisher.publishPacts(opts)

mui_ume
2019-12-20 02:41
Can someone explain this line providerBaseUrl: "http://localhost:8082",???

mui_ume
2019-12-20 02:43
Can give a clear explanation of the example for the pact consumer and provider Becos I still have to figure out from the example. How can I setup the pact provider?

matt.fellows
2019-12-20 03:05
The publisher?s job is to simply push a pact file from a local file system to a broker

matt.fellows
2019-12-20 03:05
The `providerBaseUrl` is not a valid property for this command

matt.fellows
2019-12-20 03:06
Can you explain what?s confusing about it? I?m afraid if I give another example it will be equally confusing

mui_ume
2019-12-20 03:09
Yes An explanation will be useful

mui_ume
2019-12-20 03:10
Do you have a provider for the jest example ? This example seem to be for consumer side only ?

mui_ume
2019-12-20 03:13
It didn?t work for me I put this lines in my package.json It works "scripts": {   "test:pact": "jest cross-env CI=true __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupFilesAfterEnv ./pact/pactTestWrapper.js --testMatch \"**/*.test.pact.js\"",   "publish:pact": "pact-broker publish ./pacts -a 2.0.0 --broker-token ?xxxxxxxx? -b https://test.pact.dius.com.au/",   "verify:pact": "node ./verifyPacts.js"  },

mui_ume
2019-12-20 03:13
But the provider is still not working

mui_ume
2019-12-20 03:14
My verifyPacts.js - let pact = require("@pact-foundation/pact-node") let path = require("path") let opts = {   provider: 'converse provider',   providerBaseUrl: 'http://localhost:8082',   providerStatesUrl: 'http://localhost:8082/states',   providerStatesSetupUrl: 'http://localhost:8082/setup',   pactBroker: "https://test.pact.dius.com.au/",   pactBrokerUrl: 'https://test.pact.dius.com.au/',   pactBrokerUsername: process.env.PACT_USERNAME,   pactBrokerPassword: process.env.PACT_PASSWORD,   publishVerificationResult: true,   providerVersion: '1.1.0'  } pact.verifyPacts(opts).then(() => {   console.log('success')   process.exit(0)  }).catch((error) => {   console.log('failed', error)   process.exit(1)  })

mui_ume
2019-12-20 03:15
The things is I don?t understand those providerBaseUrL What exactly are they for ?

mui_ume
2019-12-20 03:15
The pact broker is at https://test.pact.dius.com.au/ So why still need to specify the ProviderBaseURL ?

mui_ume
2019-12-20 03:16
Is it to mock the consumer ?

bethskurrie
2019-12-20 03:16
That's for verification.

bethskurrie
2019-12-20 03:17
It needs to know where to get the pacts from (the Pact Broker), and where to replay the requests against (the real provider).

mui_ume
2019-12-20 03:19
I see thanks for the clear explanation

mui_ume
2019-12-20 03:21
When I run node ./publisher.js

mui_ume
2019-12-20 03:22
I got Could not publish pact: Failed to publish converse consumer/converse provider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published

bethskurrie
2019-12-20 03:23
Can you think of some ways to debug this?

bethskurrie
2019-12-20 03:23
How can you test that the credentials you have a right using something other than the code?

mui_ume
2019-12-20 03:36
I run this command "publish:pactBroker": "pact-broker publish ./pacts -a 2.0.0 --broker-token 'xxxx' -b https://test.pact.dius.com.au/

mui_ume
2019-12-20 03:36
It works for me

mui_ume
2019-12-20 03:37
But using the publisher.js It has Authentication failed error

mui_ume
2019-12-20 03:37
Anyway I want to verify the pact How can I do it ?

mui_ume
2019-12-20 03:57
I tried running from this example https://github.com/pact-foundation/pact-js/tree/master/examples/jest I too get pactbroker::Client::error - authentication failed

mui_ume
2019-12-20 06:11
Hi Matt This providerBaseUrl is seen in the pact-js/examples/jest/publish.js

mui_ume
2019-12-20 06:26
Can someone point me to how I can setup n config the provider to verify the pact file from the pact broker ? Thanks

mui_ume
2019-12-20 07:15
My verifyPacts.js let pact = require("@pact-foundation/pact-node") let path = require("path") let opts = { provider: 'converse provider', providerBaseUrl: 'http://localhost:8082', providerStatesUrl: 'http://localhost:8082/states', providerStatesSetupUrl: 'http://localhost:8082/setup', pactBrokerUrl: 'https://test.pact.dius.com.au/', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, pactBrokerToken: process.env.PACT_TOKEN, publishVerificationResult: true, providerVersion: '1.0.0' } pact.verifyPacts(opts).then(() => { console.log('success') process.exit(0) }).catch((error) => { console.log('failed', error) process.exit(1) })

mui_ume
2019-12-20 07:15
When I run it with Node ./verifyPact.js I get this error 2019-12-20T07:02:22.232Z] WARN: pact-node@10.2.4/11352 on Lays-MacBook-Pro.local: Pact exited with code 1. failed Error: /Users/laymui/Desktop/converse-api/node_modules/@pact-foundation/pact-node/standalone/darwin-1.73.0/lib/ruby/lib/ruby/2.2.0/uri/generic.rb:400:in `check_user': bad component(expected userinfo component or user component): (URI::InvalidComponentError) from /Users/laymui/Desktop/converse-api/node_modules/@pact-foundation/pact-node/standalone/darwin-1.73.0/lib/ruby/lib/ruby/2.2.0/uri/generic.rb:377:in `check_userinfo'

mui_ume
2019-12-20 07:16
Could appreciate if anyone can give me some pointer As I?m really stuck and my colleague is waiting for me to setup this framework to test the api endpoint ?

bethskurrie
2019-12-20 10:26
So, for the test account, there is no broker token.

bethskurrie
2019-12-20 10:27
The credentials are username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1

bethskurrie
2019-12-20 10:27
Why are you using the test one and not your own one?

mui_ume
2019-12-20 10:29
Matt has replied me not to use the email extension for the username This is the one that cause the error earlier

mui_ume
2019-12-20 10:31
So my username is LayMui.toh Not This is the one that cause the error I won?t know this in the error throw out Can you add this in the doc for the benefit of future new user ?

bethskurrie
2019-12-20 10:46
Your email is only used for logging in to the UI.

bethskurrie
2019-12-20 10:47
That can't be your username for the API, because there are no usernames for the API for the broker you just signed up for.

bethskurrie
2019-12-20 10:48
That only has a token.

bethskurrie
2019-12-20 10:51
You can sign in to the UI for http://taiger.pact.dius.com.au using the username and password that were sent to you in the email when you signed up. You can authenticate to the API for http://taiger.pact.dius.com.au using the token that you will find in the settings page of your broker. You can authenticate to both the UI and API of http://test.pact.dius.com.au using the basic auth credentials that I posted above.

bethskurrie
2019-12-20 10:52
I do not know what the username LayMui.Toh could be used for.

bethskurrie
2019-12-20 10:53
There is no account with that username.

mui_ume
2019-12-20 10:54
Thanks my issue is resolved by removing the @taiger.com From the username

bethskurrie
2019-12-20 11:02
It's not throwing an error any more, but that's not a valid username.

bethskurrie
2019-12-20 11:02
It's just not raising an error because there's no @ symbol in it when it tries to create the URL with a username/password. That's what was causing the problem. You could put "abc" in there and it would do the same thing as the username you're using.

bethskurrie
2019-12-20 11:03
BTW, you don't need a username/password AND token.

bethskurrie
2019-12-20 11:03
You only ever need one or the other.

mui_ume
2019-12-20 12:19
Got it thanks Beth

mui_ume
2019-12-20 13:14
If my api is Put with a parameter Example : /api/external/bots/{bot-id} How should I specify in the path in the following code snippet? beforeEach(() => { const interaction = { state: 'Update bot', uponReceiving: 'id and BotName', withRequest: { method: 'PUT', path: urlpath, <??-

mui_ume
2019-12-21 02:22
I try the following using query - uponReceiving: 'botName and id detail', withRequest: { method: 'GET', path: urlpath, query: "bot_id=12334444" , headers: { Accept: '*/*', 'Content-Type': 'application/json',

mui_ume
2019-12-21 02:23
It didn?t work I get the error saying Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Incorrect requests: GET /api/external/bots (request query did not match) See /Users/laymui/Desktop/iconverse-api-pact-js/logs/pact.log for details.

mui_ume
2019-12-21 02:28
I have to use regular expression in the path url: urlpath + '/bot-id=/\w+/',


mui_ume
2019-12-21 02:30
Following the example given It didn?t work for me Or did I miss anything here ?

taisedias
2019-12-22 21:52
has joined #pact-js

mui_ume
2019-12-23 06:39
My publish.js file contains the token only But I still can?t publish to the pact broker

matt.fellows
2019-12-23 22:04
No I don?t have a jest provider I don?t think

matt.fellows
2019-12-23 22:05
It?s a lot of work maintaining examples for every framework, so we just accept donations from the community

matt.fellows
2019-12-23 22:05
It shouldn?t matter what framework you use, as Pact doesn?t have any framework specific things in it

bethskurrie
2019-12-24 19:33
Make sure you're using the latest version of pact-js as token support has only been added recently.

agarwalatrisha1212
2019-12-26 22:53
has joined #pact-js

mui_ume
2019-12-28 08:52
Hi, I like to check this providerBaseUrl: "http://localhost:8080", at https://github.com/pact-foundation/pact-js/blob/master/examples/jest/publish.js is referring to the port that the provider is running on? while the global.port = 8991 at https://github.com/pact-foundation/pact-js/blob/master/examples/jest/pactSetup.js is referring the mock provider service?

mui_ume
2019-12-28 08:53
I like to clarify the above as I was trying to setup the provider in the same project folder as the consumer, making it as end to end and I got some error when I run the provider to verify.

mui_ume
2019-12-28 09:02
Looking at this https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/providerService.js, server.listen(8081, () => { console.log("Animal Profile Service listening on http://localhost:8081") }),

mui_ume
2019-12-28 09:03
what is this server running at port 8081? is it the actual provider? or the mocking the consumer service?


mui_ume
2019-12-28 09:08
server.listen(8080, () => { console.log("Animal Matching Service listening on http://localhots:8080") })

mui_ume
2019-12-28 09:08
what is this server running at 8080? is it the mock provider?

mui_ume
2019-12-28 09:12
in my consumer pact test:

matt.fellows
2019-12-28 10:14
The provider base URL needs to point at your actual running provider

matt.fellows
2019-12-28 10:15
The examples you pointed out above are express JS servers. They are real servers, not the Pact mock provider

matt.fellows
2019-12-28 10:16
(this is all assuming you're doing provider side testing here)

matt.fellows
2019-12-28 10:16
No, it's a real provider

matt.fellows
2019-12-28 10:16
It's the real provider

mui_ume
2019-12-28 10:17
Okay thanks I got it

matt.fellows
2019-12-28 10:17
:+1:

mui_ume
2019-12-28 10:17
Yes I?m working on provider side now

mui_ume
2019-12-28 10:18
I like to understand what is this /setup ?

mui_ume
2019-12-28 10:18
And why do we need that ?

mui_ume
2019-12-28 10:19
Also What should I do with the state ? For my authentication api request I don?t have any database or repository like in the e2e example How should I handle that ? Is it to do assertion check on the response ?

matt.fellows
2019-12-28 10:28
Setup is an old (deprecated) way for setting up provider states. You now use the provider states property

matt.fellows
2019-12-28 10:28
There's a whole article on this in the docs.

mui_ume
2019-12-28 10:47
Oh ok will check out thanks

mui_ume
2019-12-28 22:42
When I put 2 diff states in my consumer test I got Pact verification failed - expected interactions did not match actual. I was just looking at this jest example https://github.com/pact-foundation/pact-js/blob/master/examples/jest/__tests__/index.spec.js If I could modify the example, my format will be something similar like this

mui_ume
2019-12-28 22:46
```describe("works", () => { describe("state 1", () => { beforeEach(() => { const interaction = { state: "i have a list of projects", uponReceiving: "a request for projects", withRequest: { method: "GET", path: "/dogs", headers: { Accept: "application/json", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json", }, body: EXPECTED_BODY, }, } return provider.addInteraction(interaction) }) // add expectations it("returns a sucessful body", () => { return getMeDogs({ url, port, }) .then(response => { expect(response.headers["content-type"]).toEqual("application/json") expect(response.data).toEqual(EXPECTED_BODY) expect(response.status).toEqual(200) }) .then(() => provider.verify()) }) }) describe("state 2", () => { beforeEach(() => { const interaction = { state: "i have a list of another projects ", uponReceiving: "a request for another projects", withRequest: { method: "GET", path: "/dogs", headers: { Accept: "application/json", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json", }, body: EXPECTED_BODY, }, } return provider.addInteraction(interaction) }) // add expectations it("returns a sucessful body", () => { return getMeDogs({ url, port, }) .then(response => { expect(response.headers["content-type"]).toEqual("application/json") expect(response.data).toEqual(EXPECTED_BODY) expect(response.status).toEqual(200) }) .then(() => provider.verify()) }) }) })``` ``````

mui_ume
2019-12-29 02:40
ignore the above, I got it resolved by putting the afterEach(() => provider.verify()) above and removec the .then(() => provider.verify())


mui_ume
2019-12-29 03:25
But I am still not very clear what should I do ? It mentioned The provider team sets up the relevant provider state by creating one alligator with the name Mary AND one alligator named John. Do I need to Setup a database ? Or Repository to store the expected response Maybe I used my own scenarios Let say I?m doing a authentication api I want to test 2 different state or case - valid credentials and invalid credentials? my payload is clientID, clientSecret Curl command - curl -X POST "https://iconverse-xxx.io/i-admin/api/external/authenticate" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"clientId\": \"user1\", \"clientSecret\": \"password1\"}" In my consumer test I put a state ?authentication with valid client? Another state with Authentication with invalid client So in my provider side What should be the code for the state when authentication with valid client and code for the state with invalid client Becos in my case it?s a post command not a get Do I need to create a repository with user account ? What does pact actually do when running the provider to verify the pact file ? Checking the response based on the state? So how should I describe the state to pact?

franklin.huynh
2019-12-30 00:33
has joined #pact-js

marcelo.emmerich
2020-01-06 20:33
has joined #pact-js

simone.cusimano92
2020-01-15 08:13
has joined #pact-js

davchung5
2020-01-15 22:40
has joined #pact-js

sam774
2020-01-16 14:02
has joined #pact-js

sam774
2020-01-17 10:21
Dumb question, but does pact-js support pactfile spec version 3? I can see that all the docs are using the (default) v2, so naturally our pacts are written that way too. We perform provider verification using pact-jvm (we also have some pact-jvm pacts which are v3). When I set 'spec: 3', the output doesn't look like spec v3 and the provider verification then fails.


matt.fellows
2020-01-17 10:22
the caveat is that it _does_ support messages, which is a v3 feature. But not the matchers

sam774
2020-01-17 10:27
that's fair enough - not a blocker for us being on v2 of the spec :slightly_smiling_face: thanks for the quick reply

matt.fellows
2020-01-17 10:29
Hopefully we?ll be there in the next few months, but v2 gets you pretty far

sam774
2020-01-17 10:29
aye. it was more out of curiosity than an explicit need

josue.guerrero
2020-01-17 14:51
has joined #pact-js

zoeabryant
2020-01-22 11:32
I've run into a weird error setting up a provider side verification: `Error: Cannot find module 'bunyan-prettystream'` my package.json literally has one dependecy: `"@pact-foundation/pact": "^9.6.0"`

matt.fellows
2020-01-22 21:26
Hmm. Is that during install or run?

tjones
2020-01-23 03:58
`bunyan-prettystream` is a dev dependency, when it should be a dependency

tjones
2020-01-23 03:58
I?ll fix this

tjones
2020-01-23 03:59
in the meantime, `npm install bunyan-prettystream` should workaround this issue

tjones
2020-01-23 04:06
Releasing v9.6.1 with corrected dependencies

tjones
2020-01-23 04:06
Thanks for the report!

hidalgofdz
2020-01-27 20:19
has joined #pact-js

sagupta
2020-01-28 10:45
has joined #pact-js

louiseavelar
2020-01-28 18:00
has joined #pact-js

g.j.crossfield
2020-01-28 18:25
has joined #pact-js

jana.pacheco
2020-01-29 12:46
has joined #pact-js

sagupta
2020-02-04 12:23
Hi Team, I am going through the PACT JS workshop , and I have a doubt at Step 2. https://github.com/DiUS/pact-workshop-js-v1/tree/step2 ``` it('can process the JSON payload from the provider', done => { const {fetchProviderData} = require('../consumer') const response = fetchProviderData() expect(response).to.eventually.have.property('count', 1000)``` I think this test will not pass, because fetchProviderData function returns an object which is like {value: ??, date: ??} and this doesnt have any property ?count? and this test checks for the value of count property in the response. Can someone clarify please?

antonello
2020-02-04 12:24
Perhaps I can help. what?s up?

sagupta
2020-02-04 12:30
ok i checked in the github in the file pact-workshop-js-v1/consumer/client.js , ffetchProviderData function returns {count: ??, date: ??} which is indeed TRUE but the example in the Readme file has different object returned so this needs to be corrected for all branches..

shero86
2020-02-07 10:33
has joined #pact-js

sagupta
2020-02-12 14:19
Hello , is there a way to add matching to the request path . I have a request path like this /companies/:companyId/users/:usersId For now , I have setup the interaction with the actual values of the request . However I would like to setup for all requests which can have different companyId and userId

matt.fellows
2020-02-12 19:49
Yes, there are examples in the repo for that I believe. It's the same as any other matcher but only applies on the consumer side

sagupta
2020-02-13 05:55
I have checked the repo and could only find examples for headers, query Params and body but not Path .Can you provide reference ?

matt.fellows
2020-02-15 11:56
Have you tried using the `term` matcher? That should work just fine

matt.fellows
2020-02-15 11:56
I thought there was an example but perhaps there isn?t

parveenbanu
2020-02-17 11:18
has joined #pact-js

parveenbanu
2020-02-17 12:42
Hi

parveenbanu
2020-02-17 12:42
i am new joiner here. currently in API Testing.

parveenbanu
2020-02-17 12:43
my management asked me to start with Contract Testing for API

parveenbanu
2020-02-17 12:43
so i choose PACT for it.

parveenbanu
2020-02-17 12:43
can anyone please help to setup this testing prototype

parveenbanu
2020-02-17 12:44
i have Json messages


matt.fellows
2020-02-17 19:52
And completing the workshop to understand the concepts

dominik
2020-02-19 07:55
has joined #pact-js

robin.vanwijngaarden_
2020-02-19 12:07
has joined #pact-js

mui_ume
2020-02-21 11:37
I have this url path ```const urlpath = '/uaa/oauth/token?grant_type=password&password={password}&username={username}'; how can I pass in the variable username and password ```

paolaagudelo10
2020-02-21 19:00
has joined #pact-js

mui_ume
2020-02-22 05:21
I got Actual interactions do not match expected interactions for mock MockService. Incorrect requests: POST /api/uaa/oauth/token (request query did not match) my curl command look like this: ```curl --location --request POST 'https://xxxx/api/uaa/oauth/token?grant_type=password&username=kcp-admin-taiger&password=pass' \ --header 'X-Active-Organization:1234' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Authorization: Basic abc' \ --data-raw ''```

mui_ume
2020-02-22 05:21
I put the project at https://github.com/LayMui/pact-js to reproduce. thanks

mui_ume
2020-02-22 10:12
ignore, I have resolved it

mui_ume
2020-02-24 01:22
I am trying to look up the matchers API documentation...

mui_ume
2020-02-24 01:22
need to check the difference between matcher.like, eachlike, etc


mui_ume
2020-02-24 04:55
I am trying to add the provider verification state, here is my code snippets: ```describe("Pact Verification", () => { it("validates the expectations of Authentication Service", () => { let opts = { logLevel: "INFO", providerBaseUrl: "http://localhost:8082", provider: "iProvider", providerVersion: "2.0.0", pactBrokerUrl: process.env.PACT_BROKER_URL || "http://localhost:9292", stateHandlers: { "Authenticate with valid access token": () => { }, }``` `

mui_ume
2020-02-24 04:56
right now I need to know how to add the code for the stateHandlers

mui_ume
2020-02-24 04:57
my consumer side test look like this: ```beforeEach(() => { const interaction = { state: 'Authenticate with valid access token', uponReceiving: 'access_token, token_type and refresh_token', withRequest: { method: 'POST', path: urlpath, param: { "grant-type": Matchers.like("password"), "password": Matchers.like("pass"), "username": Matchers.like("admin"), }, headers: { 'Content-Type': 'application/json', 'X-Active-Organization': Matchers.like('123'), 'Authorization': Matchers.like('Basic abc'), }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', 'X-Active-Organization': Matchers.like('123'), 'Authorization': Matchers.like('Basic abc'), }, body: Matchers.like(EXPECTED_BODY) }, }; return provider.addInteraction(interaction); });```

mui_ume
2020-02-24 04:57
it's an authentication login, how should I set the state on the provider side?

mui_ume
2020-02-24 04:57
thanks!

mui_ume
2020-02-24 09:53
I got verifyPacts.js:33 describe("Pact Verification", () => { ^ ReferenceError: describe is not defined

matt.fellows
2020-02-24 10:55
Lay, that indicates you are not running your provider verification within the contexnt of a test framework (such as mocha/Jest/?)

matt.fellows
2020-02-24 10:56
```"grant-type": Matchers.like("password"),``` I don?t think you want a string matcher here, I?m guessing it should be exactly ?password? (or whatever the valid values for grant type are)

sagupta
2020-02-24 12:42
@matt.fellows I am trying this for the matching in the request path . To allow different ids in this path /companies/<companyId>/roles withRequest: { method: ?GET?, path: `/companies/${Pact.term(generate: ?7aeeef69-ca14-5b3c-9022-565ea1b16d60?, matcher: /d{36})}/roles

sagupta
2020-02-24 12:42
doesnt work for me i am getting syntax error in the path property

matt.fellows
2020-02-24 12:47
The value of `path` should be a matcher, you can?t embed a matcher in the string value

matt.fellows
2020-02-24 12:47
`path: Pact.term(?)`

paolaagudelo10
2020-02-24 13:12
hi, i am getting warning messages after execute my tests, all of the test suite looks green, however i want to make the test fails when this kind of warns appears to force a correct test implementation i was looking for information and with jest it is possible doing something like this: ```let warn = jest.spyOn(global.console, 'warn'); /// do some test expect(warn).not.toBeCalled();``` however when i tried this does not work because the pact console is not the same that the jest console and i can access that global.console value. so i can ask if there is a way to do something like this or any other idea about how to make this test fail?

mui_ume
2020-02-24 13:45
this is not an issue however I got this error ```AIL __provider-pacts__/authentication_api.verify.pact.js Pact Verification ? validates the expectations of Authentication Service (1534ms) ? Pact Verification ? validates the expectations of Authentication Service TypeError: server.close is not a function 33 | 34 | return new Verifier(opts).verifyProvider().finally(() => { > 35 | server.close(); | ^```


sagupta
2020-02-24 14:12
ok so i tried the below in a short version of path and i get this error. Example ?/companies/7aeeef69-ca14-5b3c-9022-565ea1b16d60/? does not match provided regular expression ?/companies/w{8}-w{4}-w{4}-w{4}-w{12}/? path: term({ generate : ?/companies/7aeeef69-ca14-5b3c-9022-565ea1b16d60/?, matcher : ?/companies\/\w{8}\-\w{4}\-\w{4}\-\w{4}\-\w{12}\/? })

mui_ume
2020-02-24 14:42
I replaced line 34-35 with ``` return new Verifier(opts).verifyProvider().then(output => { console.log("Pact Verification Complete!") console.log(output) })```

mui_ume
2020-02-24 14:43
I got this error: ```Verifying a pact between iConsumer and iProvider Given Authenticate with valid access token access_token, token_type and refresh_token with POST /api/uaa/oauth/token returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which equals "application/json" (FAILED - 3) "X-Active-Organization" which is an instance of String "Authorization" which is an instance of String Failures: 1) Verifying a pact between iConsumer and iProvider Given Authenticate with valid access token access_token, token_type and refresh_token with POST /api/uaa/oauth/token returns a response which has status code 200 Failure/Error: expect(response_status).to eql expected_response_status expected: 200 got: 500 (compared using eql?)```

dan.garland
2020-02-25 10:28
has joined #pact-js

ihor.dobrovolskyi
2020-02-25 12:30
has joined #pact-js

ihor.dobrovolskyi
2020-02-25 12:34
Hello! Please explane me how can I change path for quest in `stateHandlers` section? For exampe: I need to change the UUID in request path Thanks!

bheemreddy181
2020-02-25 14:46
has joined #pact-js

matt.fellows
2020-02-25 21:58
can you please elaborate?

matt.fellows
2020-02-25 21:59
What kind of warning are you getting? Failing a Pact test based on a console log seems very strange to me. Can you please elaborate on your scenario?

aaronmckaynz
2020-02-26 05:16
has joined #pact-js

ckkinay
2020-02-26 09:36
has joined #pact-js

paolaagudelo10
2020-02-26 13:04
@matt.fellows sure, i am having the "Ignoring unsupported matching rules on arrays" warning, according to pactSupport this issue it's has been solved for body parameters https://github.com/pact-foundation/pact-js/issues/205 however the error is still appearing in matching rules for query parameters. So i want to control this and make the test fails when this warning appears.

matt.fellows
2020-02-26 21:25
Is it causing actual issues though? The ?warn? for the matchers are only there to say that it may not use a matcher (and instead use an exact value). But if the tests don?t fail on either side, why would you want to still fail it on the warning? If it?s a bug in the warning code (as it may be) then failing your test would seem silly.

matt.fellows
2020-02-26 21:26
Personally I would just ignore it

matt.fellows
2020-02-26 21:26
Perhaps I?m missing something though. @bethskurrie any thoughts?

bethskurrie
2020-02-26 21:27
This query string parameters thing is a pain.

bethskurrie
2020-02-26 21:27
It's too hard to explain why it's showing that warning, but it can be safely ignored.

bethskurrie
2020-02-26 21:27
I'm sorry about it - I've tried to fix it a few times, but it's a tricky one.

bethskurrie
2020-02-26 21:28
It's to do with the way the parameters are serialised in a v2 pact. The query is a string, but the matchers say it's a hash.

bethskurrie
2020-02-26 21:28
So the library goes "you can't apply these hash matchers to a string"

matt.fellows
2020-02-26 21:37
Thanks Beth, so yes, don?t try to spy on the pact framework and use string output to fail a test.

bethskurrie
2020-02-26 21:37
Def don't fail the test.

bethskurrie
2020-02-26 21:38
The query matchers aren't even used in the provider tests.

bethskurrie
2020-02-26 21:38
It's just a deserialization warning

paolaagudelo10
2020-02-26 22:24
Hello, @matt.fellows and @bethskurrie i solved the error by sending an exact value as you suggested, however i want to forced a right implementation in test that are going to be add into my suit, from other developers that could see a warning and just ignore.

bethskurrie
2020-02-27 05:12
@paolaagudelo10 would you be able to send me a redacted copy of the pact that is causing the issue?

bethskurrie
2020-02-27 05:13
Now I think about it, I was sure I'd actually fixed this warning.

closenet.uk
2020-02-27 16:20
hey @matt.fellows we've just been getting issue with yarn audit report an issue with PACT version due to this dependency https://github.com/kevva/decompress/issues/71

davidmolinero.com
2020-03-01 19:41
has joined #pact-js

joel.whalen
2020-03-02 17:19
has joined #pact-js

simon.nizov
2020-03-03 17:17
has joined #pact-js

simon.nizov
2020-03-03 17:24
Hi! I?m trying to debug why my provider publishes verification results for only 1 of its 2 consumers but all I can see is this: ```[2020-03-03T17:15:11.505Z] INFO: pact@9.6.0/42271 on SNizov-mbk13.local: Verifying provider [2020-03-03T17:15:11.515Z] INFO: pact-node@10.2.4/42271 on SNizov-mbk13.local: Verifying Pacts. [2020-03-03T17:15:11.516Z] INFO: pact-node@10.2.4/42271 on SNizov-mbk13.local: Verifying Pact Files [2020-03-03T17:15:19.013Z] INFO: pact-node@10.2.4/42271 on SNizov-mbk13.local: Pact Verification succeeded.``` Is there a way to configure `Verifier` to print the more verbose ruby-style output when executing? Or some other way to check out the verification logs?

matt.fellows
2020-03-03 20:55
I'm assuming you've set the publishing flag to true? It should print out that it's doing it so I'm wondering if it's publishing at all

matt.fellows
2020-03-03 20:56
I don't think there is a verbose flag but will need to check

simon.nizov
2020-03-03 21:20
@matt.fellows I did, yes. It's publishing the results of one consumer but not the other.

matt.fellows
2020-03-03 21:31
mmm

matt.fellows
2020-03-03 21:31
Is there a longer log file than that you can share (privately/redacted if necessary?)

matt.fellows
2020-03-03 21:32
(there is a `--verbose` flag on the verifier actually, so you could try to invoke the verifier locally - it will probably fail, but should publish 2 sets of verification results)

matt.fellows
2020-03-03 21:32
are the pacts it?s fetching from the Pact Broker? (assuming yes but have to ask)

simon.nizov
2020-03-03 21:43
I would if I could.. that?s really all of it :man-shrugging:

simon.nizov
2020-03-03 21:44
You mean to use the standalone executable?

simon.nizov
2020-03-03 21:44
Yep

surajkeshri
2020-03-03 21:46
has joined #pact-js

simon.nizov
2020-03-03 21:54
Ok figured it out. I?m using `consumerVersionTag: ['dev']` but one of the consumers isn?t tagged at all. Thanks @matt.fellows!

matt.fellows
2020-03-03 21:55
ahhh!

matt.fellows
2020-03-03 21:55
so that means it?s only pulling down one contract. Got it

matt.fellows
2020-03-03 21:55
hmm, how can we make that clearer?

surajkeshri
2020-03-03 21:56
Hi everyone! I'm new to this group. First of all, I love pact. I've been using it for more than a month and I'm really enjoying it. However these is one error I've frequently faced. I'm facing the "Missing request" issue when using multiple tests with the same consumer provider pair in multiple files. The weird thing about this error is that I don't get it in every run of the test suite. Also, I don't get an error when the tests are in the same file. I've tried to follow the advice in https://github.com/pact-foundation/pact-js#splitting-tests-across-multiple-files. In particular, I'm using the `merge` as the `pactFileWriteMode`. Also, I 'm running the tests using `jest --runInBand` . I've tried other modes like `update` but have not been able to solve problem. Please advice!

matt.fellows
2020-03-03 21:57
BTW what testing framework do you use @simon.nizov? I?d like to create a few wrappers for provider verification. This way, I could provide granular test feedback on a per contract, per assertion basis. So you?ll get an individual failure on ?Contract between Consumer A and Provider B > some scenario > status should be 200? type thing. I think this would make it clearer if another consumer wasn?t showing up, and also of course which exact thing wasn?t working

matt.fellows
2020-03-03 21:57
(I?m just on the train and about to swap stations, so will follow this all up when I land in the office)

simon.nizov
2020-03-03 21:57
So, the ruby verifier prints this: ```INFO: Fetching pacts for X from https://.... INFO: Reading pact at https://***:*****@mybroker/pacts/provider/X/consumer/Y/version/1.0.15074.dev``` And then this for the second consumer ```INFO: Reading pact at https://***:*****@mybroker/pacts/provider/X/consumer/Z/version/1.0.3574.dev``` Which is helpful

matt.fellows
2020-03-03 21:58
Can you please share your code? Redacted if necessary. This smells of a promise not being correctly handled

surajkeshri
2020-03-03 21:58
Yes

simon.nizov
2020-03-03 21:59
Also each of those has a line like this at the end: ```INFO: Verification results published to https://...```

simon.nizov
2020-03-03 22:00
I?m using Jest. But the verification step is just a .js file that I added as a script to `package.json` and I run during our CI build.

matt.fellows
2020-03-03 22:02
Got it. I'll try and spike what I mean in the next week or so and ping this channel when I have it. I think it will help this situation

simon.nizov
2020-03-03 22:02
Cool, thanks for the help!

surajkeshri
2020-03-03 22:03
One thing to note is that I'm using pact-jest library which makes it easy to setup provider. See pactWith test block in both files.

matt.fellows
2020-03-03 22:06
Is addUser a promise? Can you also share the log file that talks about mismatches? That will help see the sequence of events from the perspective of Pact

surajkeshri
2020-03-03 22:07
No addUser is a sync function: ```export const addUser = (client: ApolloClient<any>, userId: string) => { // const graphqlClient = createClient({ graphqlURL: url || '' }); client.writeQuery({ query: CURRENT_USER, data: { authStatus: { userId: userId || null, signinError: null, signupError: null, signupSuccess: null, __typename: 'authStatus', }, }, }); };```

surajkeshri
2020-03-03 22:10
Error jest log ``` FAIL src/components/auth/initial-profile-setup.spec.tsx (5.054s) ? Console console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: POST /graphql See /Users/surajkeshri/Documents/Developer/crewhood/frontend/pact/logs/Frontend-GroupService-mockserver-integration.log for details.```

surajkeshri
2020-03-03 22:10
Note that the log file is overwritten everytime a different test file runs with the same consumer provider pair so in thisw case it didn't show any missing request in log file.

surajkeshri
2020-03-03 22:12
Here's the pact file which has all the interactions:

surajkeshri
2020-03-03 22:13
so none of thee interactions are missing in the pact file but I think when the test is run maybe the files are not written before that and there is delay so the test ends up not finding the interaction?

matt.fellows
2020-03-03 22:14
Yeah that log file looks ok. If you only run one of the tests can you ever get it to fail? Or is it only when you combine them?

matt.fellows
2020-03-03 22:15
Are you running them on a different mock server port? That matters too (sorry on mobile)

surajkeshri
2020-03-03 22:16
No one test always passes

surajkeshri
2020-03-03 22:16
yes a new port is created every time Ithink

surajkeshri
2020-03-03 22:17
I can force the same port though if you'd suggest me trying that

surajkeshri
2020-03-03 22:22
so it tried same port for the Frontend-GroupService pair and I got the same error. (One out of 7 times I think)

matt.fellows
2020-03-03 22:33
thanks

matt.fellows
2020-03-03 22:33
I?m confused about how ```addUser(apolloClient, userId);``` is not a promise - it?s making a network call right? If so, I don?t know how it can?t be one

surajkeshri
2020-03-03 22:35
this function is just adding some data to the cache. Here's the signature of the function: ```writeQuery<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteQueryOptions<TData, TVariables>): void;```

matt.fellows
2020-03-03 22:35
ah ok

matt.fellows
2020-03-03 22:37
so what line is responsible for the http request that makes the graphql post?

surajkeshri
2020-03-03 22:38
That is done when I render the component using the render function. For instance, for landing.tsx here's the react component (the apollo client query makes the graphql call): ```import React from 'react'; import gql from 'graphql-tag'; import styled from 'styled-components'; import { useQuery } from '@apollo/react-hooks'; import tw from 'tailwind.macro'; import { user } from '../../generated/user'; import { Nav } from './nav'; import { useAuth } from '../../auth-api'; const Wrapper = styled.div``; export const GET_USER_PROFILE = gql` query user($id: String!) { user(id: $id) { id email name avatarUrl __typename } } `; export const Landing: React.FC<{}> = () => { const [{ userId }] = useAuth(); const result = useQuery<user>(GET_USER_PROFILE, { variables: { id: userId }, skip: !userId, }); return ( <Wrapper> {result?.data?.user && ( <span className="text-bold text-black font-lg">{`Welcome ${result.data?.user.name}`}</span> )} <Nav /> </Wrapper> ); };```

matt.fellows
2020-03-03 22:41
Ah, I see. I?m not a React expert but I follow. Ideally, I would separate the tests from the UI layer


surajkeshri
2020-03-03 22:42
Yeah I'd too but this has become the standard with this library. They want the data fetching to live inside the component and it's hard to separate them.

matt.fellows
2020-03-03 22:42
I see

matt.fellows
2020-03-03 22:42
I can understand why, it just makes your tests a little messy. But let?s work through it

surajkeshri
2020-03-03 22:43
ApolloClient has their own data fetching mocking thing but I think Pact works much better because it actaully captures the interaction which can be verified by the provider.

matt.fellows
2020-03-03 22:43
got it

matt.fellows
2020-03-03 22:44
```const result = useQuery<user>(GET_USER_PROFILE, { variables: { id: userId }, skip: !userId, });``` So, presumably _that_ is the thing that makes the call and is a Promise?

surajkeshri
2020-03-03 22:44
yeah so this call ```const result = useQuery<user>(GET_USER_PROFILE, { variables: { id: userId }, skip: !userId, });``` makes the request

surajkeshri
2020-03-03 22:45
and that's the graphql request that I'm mocking by adding this interaction: ```const getUserProfileInteraction = createGraphqlInteraction({ query: GET_USER_PROFILE, variables: { id: userId }, responseBody: { data: { user: { name: pact.Matchers.like('Some name'), avatarUrl: pact.Matchers.like(avatarUrl), id: userId, email: pact.Matchers.like(email), __typename: 'User', }, }, }, uponReceiving: 'getUserProfile', state: `user with id ${userId} exists`, requestHeaders: { 'x-auth': JSON.stringify({ userId }) }, });```

matt.fellows
2020-03-03 22:46
Is there any log file that has the failure logged in it? Unfortunately, everything so far looks like it?s working!

matt.fellows
2020-03-03 22:47
I think you can specify the log file for each `pactWith` - so perhaps set them to different files so we can see what?s happening?

surajkeshri
2020-03-03 22:47
okay let me try that

matt.fellows
2020-03-03 22:48
ta

surajkeshri
2020-03-03 23:06
okay so I separated out the log and pact file folder for both the tests. Here's the log and the interaction file for the error:

surajkeshri
2020-03-03 23:36
so as I see it in the logs: the two interactions are being registered with OperationName `InitialProfile` and `EditInitialProfile`. When a request is received for the first interaction it is matched (line 152). For the second request, it says (line 192-199) ```WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /graphql W, [2020-03-03T18:03:52.508802 #67660] WARN -- : Missing requests: POST /graphql``` In the DEBUG part though, it is calling the request with the same operation name EditInitialProfile and it does match the regex of that registered interaction. But somehow it didn't detect that. But later on on line 229 it says that it found the matching response for that request. I think the bug is that it is not finding the interaction the first time as shown above but it does find it later? How can it say that the interaction is missing the first time and then find it later for the same request?

osirisnos4a2
2020-03-03 23:51
has joined #pact-js

surajkeshri
2020-03-04 22:18
Hi Matt, does this error make sense? I have not been able to debug this yet.

matt.fellows
2020-03-05 06:51
OK, so reading that log things are clearer. This is the events as far as the Pact system is concerned: 1. You register an expectation for InitialProfile 2. You register an expectation for EditInitialProfile 3. You then make a request for InitialProfile and it finds a response 4. Something is then calling the ?verify? method because it starts to check if requests (1) and (2) have happened - but only InitialProfile has happened - so it errors saying it?s missing EditInitialProfile 5. at about the same moment, a request comes in for EditInitialProfile and the server responds to that (hence why it found it) Missing requests are not that Pact couldn?t find it, but that your code didn?t make the request before you called verify. This smells of a) promises not resolving correctly or b) two sets of tests talking to the same mock service. The mock service is stateful, you can?t have parallel tests communicating to it. I?m not sure if that?s an issue with the jest-pact library your using or in your setup. But you need to find out why those things are happening concurrently.

matt.fellows
2020-03-05 06:55
I?m wondering if the wait 0 is not long enough? ``` const button = await findByText(/looks good/i); userEvent.click(button); await wait(0);``` In any case, there is an asnchronous event there (the click) and I?m pretty sure that?s why the request is coming in too late - the test will complete, and the `afterAll` hook that runs verify will kick in creating a race condition between the call editInitialProfile and the verification process. I think this is the source of your flakiness

matt.fellows
2020-03-05 10:35
(Sorry for the delay)

tyler.rasor
2020-03-05 12:58
has joined #pact-js

surajkeshri
2020-03-05 19:22
This is helpful, thanks. I've delve deeper today.

surajkeshri
2020-03-08 01:55
Hi Matt, I think you debugged it perfectly!!! Thank you so much. I just increased the wait to 10ms and ran the test for 15 times without any error. :clap:

tjones
2020-03-09 12:28
Late to the party here - glad you got the issue fixed, but I have a question - I?ve heard about this graphql library where data fetching is part of the component rendering. I?m not a graphql user myself, but this sounds like a very unhelpful pattern (among other reasons, it couples UI testing to API testing, which causes issues like the one you?ve discovered). Is this the standard for graphql? Or just this particular pattern/library for graphql? Could you tell us a bit more about it? None of the core pact js people are heavy graphql users, so I?m interested to know how we could better support it.

tjones
2020-03-09 12:29
If this is a common pattern, do you think there?s a way we could provide wrappers that make it easier to write pact tests for fetches during renders?


matt.fellows
2020-03-09 12:39
If I understand correctly, the `useQuery` bit can be tested separately from the component itself - most documentation just shows it all together

matt.fellows
2020-03-09 12:40
I would probably want a layer between `useQuery` and my component, but then you might just be re-inventing the GraphQL library. It has the ?only doing it for testability? smell

aaron
2020-03-09 21:36
has joined #pact-js

bsigney
2020-03-13 05:11
has joined #pact-js

matt.fellows
2020-03-16 06:07
Thanks Tim for your PR/Issues rampage

tjones
2020-03-16 06:07
Raargh!

matt.fellows
2020-03-16 06:07
(TODO item removed from tomorrow :stuck_out_tongue: )

tjones
2020-03-16 06:07
I mean, um, you?re welcome

tjones
2020-03-16 06:08
releasing a new pact-js now

tjones
2020-03-16 06:10
v9.8.1 - security fixes, and CORS headers improved.

matt.fellows
2020-03-16 06:10
ah yes - I actually think there is a failing Pact test for Pactflow that needs that. I?ll confirm tomorrow

tjones
2020-03-16 06:10
party on!

uglyog
2020-03-17 06:59
:point_up: we have an initial version of Pact-JS with V3 and XML support

uglyog
2020-03-17 06:59
But only for linux and OSX and node 10 and 13

bethskurrie
2020-03-17 07:27
Amazing work @uglyog and @matt.fellows!

matt.fellows
2020-03-17 07:28
I'll take whatever credit Ron is willing to concede

tjones
2020-03-17 07:28
haha!

tjones
2020-03-17 07:28
awesome!

tjones
2020-03-17 07:29
I just want to know how he did this: > uglyog > Release - v10.0.0-beta.1

uglyog
2020-03-17 07:32
hmm, no, you probably don't want to know how I did that :smile:

tjones
2020-03-17 07:33
hahaha!

bradyzp
2020-03-17 17:59
has joined #pact-js

arho.huttunen
2020-03-18 19:02
has joined #pact-js

uglyog
2020-03-20 02:30
@matt.fellows @tjones I've added some initial docs on the V3 version :point_right: https://github.com/pact-foundation/pact-js#pact-js-v3

tjones
2020-03-20 02:38
This is exciting! Nice work

bethskurrie
2020-03-22 09:48
Pact node doesn't shorten the git sha when it publishes a pact or verification does it peeps?

matt.fellows
2020-03-22 09:48
Nope. Pass thru

bethskurrie
2020-03-22 09:50
Ta

bethskurrie
2020-03-22 09:51
And can verbose mode be switched on?

bethskurrie
2020-03-22 09:52
So it logs the requests and responses?

matt.fellows
2020-03-22 09:53
Off the top of my head I can't recall. But it literally just maps to the args for the Ruby CLI. I think debug mode should show the args sent to the CLI exec'd process

tjones
2020-03-23 01:05
If verbose mode is an option for the standalone verifier, pact-node doesn?t know about it

tjones
2020-03-23 01:05
this is an easy change, and I could get it out today if you need it

bethskurrie
2020-03-23 01:05
the related issue was fixed

bethskurrie
2020-03-23 01:05
user error

bethskurrie
2020-03-23 01:05
but yes, please do expose --verbose

bethskurrie
2020-03-23 01:05
it helps debug issues communicating with the broker

tjones
2020-03-23 01:05
cool - if you have a moment, could you open a ticket?

bethskurrie
2020-03-23 01:05
pact node or js?


tjones
2020-03-23 01:06
Thank you!

matt.fellows
2020-03-23 02:55
@tjones thanks for doing https://github.com/pact-foundation/pact-node/commit/2c681ef4d7b517229cbd5e96fc8db74d6a77713b. It?s been on my mind. FWIW I think we should do https://docs.travis-ci.com/user/build-stages. Because for e.g. if linux passes but OSX fails, or another Node Version fails, it will still release

matt.fellows
2020-03-23 02:55
using build stages would prevent that

tjones
2020-03-23 02:56
Ah yes, good point. My ?pact lunch? is almost up, so I?ll make an issue for that

matt.fellows
2020-03-23 02:58
:smile:

matt.fellows
2020-03-23 02:58
?Pact lunch?


matt.fellows
2020-03-23 03:04
thx

tjones
2020-03-23 03:04
don?t thank me yet - looks like I broke pact-js

tjones
2020-03-23 03:04
but not too seriously

matt.fellows
2020-03-23 03:07
:smile:

tjones
2020-03-23 03:09
Also: The tests seem to pass on travis, but fail locally for me: ``` 1) Net #isPortAvailable when the no local hosts are available returns a rejected promise: AssertionError: expected promise to be rejected but it was fulfilled with undefined```

tjones
2020-03-23 03:09
have you seen this before?

matt.fellows
2020-03-23 03:14
mmmm no, let me try now

uglyog
2020-03-23 03:19
I found that fails on OSX

uglyog
2020-03-23 03:19
In Travis it has: sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0

tjones
2020-03-23 03:21
Yep. I?ve removed the test. The comment about node having a particular behaviour is incorrect

tjones
2020-03-23 03:21
> In most operating systems, listening to the unspecified IPv6 address (::) may cause the net.Server to also listen on the unspecified IPv4 address (0.0.0.0). https://nodejs.org/api/net.html#net_server_listen_options_callback

tjones
2020-03-23 03:22
^ this is what the documentation says

grzegorzkrol90
2020-03-23 08:31
has joined #pact-js

vitaliy.grigoruk
2020-03-24 08:44
Hi everybody. Is there a way to tell `Verifier` to run verification with all versions of a contract tagged with a specific tag (not only `latest` versions)? Our `consumer` is an iOS app and we would like to make sure that all versions that were released to AppStore (all of them are tagged with `release`) are verified every time there is a change on provider side.

bethskurrie
2020-03-24 09:02
Yes

bethskurrie
2020-03-24 09:03
But it's in a feature that's in beta.

matt.fellows
2020-03-24 09:03
Ah, we haven't added that to pact js yet have we? Just pending pacts?

bethskurrie
2020-03-24 09:04
It's just making use of the new api

matt.fellows
2020-03-24 09:04
I should be able to get a start on that later tonight. It's not a lot of work but the type system doesn't yet support it

matt.fellows
2020-03-24 09:04
BBL I'll follow up

bethskurrie
2020-03-24 09:04
Are you using Pactflow or OSS broker @vitaliy.grigoruk?

bethskurrie
2020-03-24 09:05
Sorry, I can't remember!

vitaliy.grigoruk
2020-03-24 09:05
I?m using pactflow

bethskurrie
2020-03-24 09:06
So, if you want it asap, I can tell you how to hack it. If you're OK to wait, Matt might be able to get the official support out reasonably quickly.

bethskurrie
2020-03-24 09:06
Matt, it's just passing in the consumer version selectors.

vitaliy.grigoruk
2020-03-24 09:07
I?d appreciate if you can share some info how this could be done now

bethskurrie
2020-03-24 09:07
The underlying code is already using the new api

vitaliy.grigoruk
2020-03-24 09:08
so it is just about passing the right command line args to `pact-provider-verifier`?

bethskurrie
2020-03-24 09:09
Yes.

bethskurrie
2020-03-24 09:09
There's a new --consumer-version-selector parameter


bethskurrie
2020-03-24 09:10
There's the master issue ^^

bethskurrie
2020-03-24 09:10
It describes how to use the new API.

bethskurrie
2020-03-24 09:10
What you could do is call the API directly, to get the list of pacts to verify.

bethskurrie
2020-03-24 09:11
And then feed that into your pact js configuration.

bethskurrie
2020-03-24 09:12
Do a POST to `pacts/provider/{provider}/for-verification` with the body ```{ "consumerVersionSelectors": [ { "tag": "prod" } ] }```

bethskurrie
2020-03-24 09:13
That will return a list of pact verification objects (deduped so that if multiple pacts have the same content, it only gets verified once). You can pull the pact URLs out, and then manually configure pact-js to verify those URLs.

bethskurrie
2020-03-24 09:13
Does that make sense?

bethskurrie
2020-03-24 09:15
If you're using can-i-deploy, then you can already specify "all versions of this particular consumer". Docs are here: https://github.com/pact-foundation/pact_broker-client#alternate-usage---specifying-dependencies-explicitly

bethskurrie
2020-03-24 09:16
See the "Mobile provider use case".

vitaliy.grigoruk
2020-03-24 09:17
Thank you @bethskurrie, I?ll try this!

bethskurrie
2020-03-24 09:17
We'll make an announcement when it's out in the js code.

vitaliy.grigoruk
2020-03-24 09:23
It looks like there is no way to specify `consumer` name filter for `pacts/provider/{provider}/for-verification` .

vitaliy.grigoruk
2020-03-24 09:24
we have only 1 mobile consumer (where we need to verify all `release` contract versions) and all other consumers are web apps (where we need to verify only `latest` version

bethskurrie
2020-03-24 09:25
Fair point.

bethskurrie
2020-03-24 09:25
Easily added

bethskurrie
2020-03-24 09:26
I was expecting to do it, but nobody had asked yet.

bethskurrie
2020-03-24 09:26
I've got an OSS day tomorrow. I'll see if I can add it then.

bethskurrie
2020-03-24 09:29
If you were in a super hurry, you could do a nasty match on the urls!

vitaliy.grigoruk
2020-03-24 09:30
yeah, that?s what I was also thinking about :slightly_smiling_face:

bethskurrie
2020-03-24 09:33
Do one query to get the latest prod pacts (you'll need to put latest:true in the selector) and one to get all the prod pacts, and just keep the ones for the consumer you care about.

matt.fellows
2020-03-24 12:44
I'll look at this tomorrow @vitaliy.grigoruk

vitaliy.grigoruk
2020-03-24 12:58
great. Looking forward to that. Ping me if I can help somehow

aliihlail
2020-03-24 18:44
has joined #pact-js

audun.halland
2020-03-24 21:33
has joined #pact-js

audun.halland
2020-03-24 21:40
Hi, I?m trying `10.0.0-beta.2` with typescript, There?s a problem importing the module. In my `node_modules/@pact-foundation/pact/package.json` it says `{ ... "types": "./dist/pact.d.ts", ... }`, but the source files themselves are not in `./dist/` but at the same level as the `package.json`. I?m no JS expert, but this is how far I?ve come debugging the problem..

uglyog
2020-03-24 22:05
:point_up: @matt.fellows is that just the package file that needs to be corrected?

matt.fellows
2020-03-24 22:06
Let me take a quick look

matt.fellows
2020-03-24 22:07
yes I think so. In the `v3.0.0.` branch they point at `dist` but in master they are relative

matt.fellows
2020-03-24 22:08
Long term, I think I need to change the way the release works. There were reasons for having it in `dist` separate to compiling alongside the project (I think it was much harder to exclude certain things.

audun.halland
2020-03-24 22:31
I hacked the problem locally, and now I think I?m a bit closer:

audun.halland
2020-03-24 22:31
``` dlopen(/Volumes/uf4/pact-typescript-lib/node_modules/@pact-foundation/pact/native/index.node, 1): no suitable image found. Did find: /Volumes/uf4/pact-typescript-lib/node_modules/@pact-foundation/pact/native/index.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 /Volumes/uf4/pact-typescript-lib/node_modules/@pact-foundation/pact/native/index.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00```

audun.halland
2020-03-24 22:31
@uglyog

audun.halland
2020-03-24 22:34
This is on a mac using `yarn` (not npm) to install the package

audun.halland
2020-03-24 22:36
`file` info on this file is `ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=e0643a965bfb7ae3a0896a88b96e042af4e2833e, with debug_info, not stripped`

uglyog
2020-03-24 22:38
The NPM package has an linux image in (it should not have any)

uglyog
2020-03-24 22:39
The npm install command has a ` --update-binary` argument to get it to replace that binary with the correct one

audun.halland
2020-03-24 22:40
Yes, but I?m not using npm :stuck_out_tongue: Need to find another way then

uglyog
2020-03-24 22:41
Yeah, I'm just looking for a yarn alternative

audun.halland
2020-03-24 22:42
I searched it but cannot find anything

uglyog
2020-03-24 22:42
But you can download the binary from the releases and unpack it into the node modules

audun.halland
2020-03-24 22:42
yes, I?ll try that, thanks

uglyog
2020-03-24 22:42
That is what node-gyp does on install

uglyog
2020-03-24 22:43
The next release will not have the linux binary in the NPM package

uglyog
2020-03-24 22:52
That's going to be a problem for a lot of people!

audun.halland
2020-03-24 23:00
`sudo xattr -d com.apple.quarantine node_modules/@pact-foundation/pact/native/index.node` solved it

audun.halland
2020-03-24 23:02
`Error: Pact verification failed - expected interactions did not match actual.` :tada:


uglyog
2020-03-24 23:05
I'll update the readme with those instructions

audun.halland
2020-03-24 23:59
Hm, I actually need to use `new PactV3(..)` to use this right?

audun.halland
2020-03-24 23:59
`new Pact(..., spec: 3)` won?t work?

audun.halland
2020-03-25 00:21
Ok, given this is true, I have question about the new PactV3 API. It looks like it?s designed to have all tests against the mock server executed in a callback. The old API uses lifecycle control functions. That means upgrading won?t be painless..

audun.halland
2020-03-25 00:36
Also I have a scenario where a single test is calling several endpoints in different providers. Think GraphQL-servers fetching data from many endpoints. The _test abstraction_ is executing a graphql query, and I?ll verify that the set of correct REST endpoints are called in the other end.

audun.halland
2020-03-25 00:40
It?d been nice to still have a way to control the mock servers via lifecycle calls. Either way it?s better than spawning ruby processes, because these Rust mock servers will die along with the node process anyway.

tjones
2020-03-25 00:51
Hi @audun.halland! Thanks for the feedback, this is very useful. I haven?t had time to look at the V3 branch yet (although I?m excited about it) - I?m hoping to be able to have the upgrade as painless as possible. Your test scenario is interesting. If it were me, I?d probably want to split the test boundaries so that Pact covers each individual request/ response, and unit tests cover joining the data returned together (since the join would be done after the request was serialised into a data object). Is that possible in your case?

uglyog
2020-03-25 00:52
What are lifecycle control functions?

uglyog
2020-03-25 00:54
We decided to keep the new API separate so it won't impact existing V2 tests, but it can be merged in the future

audun.halland
2020-03-25 01:02
I mean like `async Pact.verify()`, `async Pact.finalize()`

audun.halland
2020-03-25 01:05
@tjones this is what I would normally do in a language that has proper typed deserialization of JSON responses. In a dynamic language like JavaScript there?s no ?deserialization? so I normally prefer to have fatter tests. If not, there?s almost no code changes that will be able to fail the tests. Something like ?test entropy??

uglyog
2020-03-25 01:16
Those lifecycle functions are a limitation of using the ruby mock server. We are no longer constrained by those. We could use the same format, but I don't see the benefit apart from ease of switching from V2 to V3. I would prefer to create a better DSL and than one constrained by previous implementation.

audun.halland
2020-03-25 01:24
But that also happens to fit quite nicely into several JS test frameworks. E.g. A function runs before all the tests in the suite: The mock server is started. Another function runs after the group of tests: The mock server is killed. In e.g. Jest this is `beforeAll`/`afterAll` that are both asynchronous.

uglyog
2020-03-25 01:26
We can definitely support that flow, if that is what makes sense

audun.halland
2020-03-25 01:29
There are of course other ways to do things, but I personally don?t like to use _two_ test frameworks at the same time. (test must be executed from a pact callback and that runs inside jest)

tjones
2020-03-25 01:57
I don?t think Jest constrains us to a particular way of thinking about the DSL. I do agree that there are challenges with typesafety in Pact testing with javascript, but I think those exist wherever you cut the Pact boundary (and they also exist in general unit tests too). I usually mitigate that with fixtures - I?ve been meaning to write that up in a blog post.

tjones
2020-03-25 01:58
Or do you mean you want to run pact tests without a test runner framework?

tjones
2020-03-25 02:00
Making a separate thread for discussing test frameworks / test design so as not to clutter the V3 conversation above. @audun.halland, are you aware of: https://github.com/pact-foundation/jest-pact ?

audun.halland
2020-03-25 02:09
I understand the desire to automatically shut down the mock server after the test is done. Which this type of structure _will_ solve: ```it('tests stuff', async () => { const pact = new PactV3(...); pact.executeTest(async () => { // actual test }); };``` Still I don?t think it?s flexible enough to serve all users? needs.

audun.halland
2020-03-25 02:19
I wasn?t aware of it. It looks nice for simple usage, but I?m still fond of the flexibility in being able to execute against several providers in the same test. We _do_ sometimes use pact as part of integration test, even though I?m aware it?s not considered best practice. In some cases I think it?s the lesser evil..

uglyog
2020-03-25 02:20
We can support both forms

audun.halland
2020-03-25 02:31
I think apollo server is a good example. In a consumer test I want to verify that what the REST returns actually works mapping to into a GraphQL node tree. There?s usually a very thin layer between the ?back? REST client and the ?front? graphql server. Just writing a full end2end integration test saves time and many code lines :slightly_smiling_face:

audun.halland
2020-03-25 02:34
(and sometimes that kind of test will involve calling into more than one provider)

jwortmann719
2020-03-25 10:51
has joined #pact-js

jwortmann719
2020-03-25 10:53
Hi, does anyone knows if there is already an `ng add` library to add a pact configuration to an angular app? Would love to work on something like this

matt.fellows
2020-03-25 10:55
Oh, no I?m not aware - but please do!

cesar.lopes
2020-03-25 11:13
has joined #pact-js

matt.fellows
2020-03-25 12:08
@audun.halland thanks for the feedback. I actually would like to schedule a bit of a round table before the V3 interface is fully published. Right now, it?s in a very functional but also somewhat experimental state

matt.fellows
2020-03-25 12:08
The broader ecosystem, developer ergonomics and extensibility need to be considered

matt.fellows
2020-03-25 12:09
For example, we need to be able to support code debugging, developers should be able to wrap interfaces over the system - e.g. GraphQL - and it should be extensible and publish hooks so that Pact Jest and similar wrappers can modify the ergonomics/experience as desired

matt.fellows
2020-03-25 12:10
Ultimately, we won?t be able to satisfy all of the things, and the limitations of the underlying engine (Rust) will result in tradeoffs against flexibility. But it?s an exiting development!


vitaliy.grigoruk
2020-03-25 21:09
~Maybe I?m doing something wrong, but for some reason pactflow returns me contracts with tags that do not match `consumerVersionSelectors` Here is the request I send:~ ``` curl --silent -XPOST -H "Content-Type: application/json" \ -H "Authorization: Bearer $PACT_BROKER_TOKEN" \ -d '{"consumerVersionSelectors":[{"tag": "release"}]}' \ https://$http://COMPANY.pact.dius.com.au/pacts/provider/api/for-verification```

vitaliy.grigoruk
2020-03-25 21:10
Maybe I?m doing something wrong, but for some reason pactflow returns me contracts with tags that do not match `consumerVersionSelectors` Here is the request I send: ```curl --silent -XPOST -H "Content-Type: application/json" \ -H "Authorization: Bearer $PACT_BROKER_TOKEN" \ -d '{"consumerVersionSelectors":[{"tag": "release"}]}' \ https://$http://COMPANY.pact.dius.com.au/pacts/provider/api/for-verification```

vitaliy.grigoruk
2020-03-25 21:11
I?m fetching contract URLs using jq: ```jq -r '._embedded.pacts | .[] | ._links.self.href | select(. | contains("consumer/ios-app"))'```

vitaliy.grigoruk
2020-03-25 21:13
I?ve noticed that some contract URLs refer a consumer version that doesn?t have `release` tag.

ravi.dasari
2020-03-25 21:30
has joined #pact-js

ravi.dasari
2020-03-25 21:33
@here how do I use pending pacts beta feature ? is there any documentation for this? I simply cannot find anything related to this except for the blog - http://blog.pact.io/2020/02/24/how-we-have-fixed-the-biggest-problem-with-the-pact-workflow/

matt.fellows
2020-03-25 21:47
How did you hear about it (apart from that blog)? It's not yet in JS yet (I submitted a OR to Pact Node last night that would be the key thing in doing so, however)

matt.fellows
2020-03-25 21:48
There is an environment variables you can use in the meanwhile, I'll share when back at a desk

bethskurrie
2020-03-25 22:16
You won't be seeing consumer versions in the URLs, you'll be seeing pact versions.

bethskurrie
2020-03-25 22:21
It's the "permalink" to the underlying content, not the URL that has the consumer version in it.

matt.fellows
2020-03-25 22:25
you need to a) be using http://pactflow.io and b) have exported `export PACT_BROKER_PACTS_FOR_VERIFICATION_ENABLED=true` @bethskurrie is (a) still a prerequisite?

bethskurrie
2020-03-25 22:25
no

matt.fellows
2020-03-25 22:25
:ok_hand:

bethskurrie
2020-03-25 22:25
You need to have the Pact Broker running with PACT_BROKER_FEATURES=pacts_for_verification

bethskurrie
2020-03-25 22:26
Also, you need to have an implementation that supports it, of which only the Ruby impl and standalone/dockerized pact-provider-verifier does.

bethskurrie
2020-03-25 22:28
I believe pact-js and pact-go are not far off @matt.fellows

bethskurrie
2020-03-25 22:29
pact-js just needs the `--enable-pending` flag exposed

bethskurrie
2020-03-25 22:30
If it's using the ruby stdout rather than doing any fancing parsing, it'll all just work.

bethskurrie
2020-03-25 22:34
Actually, I think pact-python does too.

matt.fellows
2020-03-25 22:34
Pact Go supports it - I should add some docs actually

matt.fellows
2020-03-25 22:34
Pact JS - sent a PR for that last night, in review

bethskurrie
2020-03-25 22:34
@ravi.dasari which language are you verifying in?

matt.fellows
2020-03-25 22:49
I?m assuming JS given we?re in this chanel

matt.fellows
2020-03-25 22:49
@bethskurrie JS is just waiting on this PR: https://github.com/pact-foundation/pact-node/pull/217

tjones
2020-03-26 00:50
Publishing that now :+1:

bethskurrie
2020-03-26 01:54
You should be able to check this by opening the matrix page and selecting "all versions with tag release" for that application.

bethskurrie
2020-03-26 01:55
The pact version sha isn't shown in the text columns unfortunately, but it is shown in the hover over text for the Pact Published column.

bethskurrie
2020-03-26 01:56
You should be able to find a row with a matching pact version sha. If you can't, then I can investigate it further for you.

ravi.dasari
2020-03-26 02:33
@bethskurrie thanks for the reply. I am using consumer with pact-js and provider for both node-js and java platforms. So I think I need this feature for both pact-js and pact-jvm.

bethskurrie
2020-03-26 03:15
It'll be a little while before pact JVM gets it, but Ron is working on it.

vitaliy.grigoruk
2020-03-26 08:28
I?m opening a first URL from the list that is returned by `curl` And it renders a page which shows pact contract for a specific version of consumer. And this versions has no tags at all?

bethskurrie
2020-03-26 08:29
That'll be the latest consumer version that has that pact content.

bethskurrie
2020-03-26 08:30
Technically, when you access a pact-version, it should show a list of all the consumer versions that have that content.

bethskurrie
2020-03-26 08:30
For better or worse, when I designed this resource, I made it select the most recent consumer version to display.

bethskurrie
2020-03-26 08:34
This API returns a list of Pact Versions, not a list of Pact Publications. I wanted to make the resources pretty much interchangeable though, so when you view a Pact Version resource, it picks the most recent Pact Publication that it belongs to.

vitaliy.grigoruk
2020-03-26 08:34
thanks for clarifications. Now it is more clear why I get these results.

bethskurrie
2020-03-26 08:36
With the benefit of hindsight, I should not have specified the consumer version resource at all, or made it a list, or made it a pb:latest-consumer-version relation.

vitaliy.grigoruk
2020-03-26 08:38
Is there any way to query API for all ?pact publications? that belong to the same ?pact-version??

bethskurrie
2020-03-26 08:39
no

bethskurrie
2020-03-26 08:39
it wouldn't be hard, but nobody has ever asked for it

bethskurrie
2020-03-26 08:39
what would you use it for?

bethskurrie
2020-03-26 08:40
btw, I'll have your "all prod pacts for this consumer" api out tomorrow.

bethskurrie
2020-03-26 08:40
and the get/post thing fixed

vitaliy.grigoruk
2020-03-26 08:40
was just curious if this is possible now to see how many pact publications belong to a particular version of the contract

vitaliy.grigoruk
2020-03-26 08:41
great, thank you very much!

bethskurrie
2020-03-26 08:41
You may be able to reverse engineer it from the matrix query.

bethskurrie
2020-03-26 08:44
ah, no. it uses the link with the consumer version.

bethskurrie
2020-03-26 08:44
If you go to the matrix page though, and hover over the pact publication cell, it will highlight all the pact publications that have the same pact version.

vitaliy.grigoruk
2020-03-26 09:00
> If you go to the matrix page though, and hover over the pact publication cell, it will highlight all the pact publications that have the same pact version. This actually works, thanks!

cesar.lopes
2020-03-26 21:31
Hey there, I?m trying to run a graphQL pact, how should I format the query: ```Matching keys and values are not shown { "body": { - "query": /\s*query\s*storeById\(\$id: + "query": "query storeById($id: String } } ```

deepakverma
2020-03-26 21:59
has joined #pact-js

matt.fellows
2020-03-26 22:12
Double check the issues online on Pact JS, I believe this may have come up before

rbenbolton
2020-03-26 22:57
has joined #pact-js


cesar.lopes
2020-03-27 09:13
any workaround for this?

cesar.lopes
2020-03-27 10:36
had to copy request body from apollo client and added __typename to the response, it works :smile:

matt.fellows
2020-03-27 12:16
Thanks. If you?re able to help work out how we can fix this in the GraphQL interaction types, I?d very much appreciate it

jwortmann719
2020-03-27 12:21
I started to work on a pact schematic. One can find the repo here https://github.com/JWO719/ngx-pact in case anyone wants to support or give feedback. I plan to release a first version just with scaffolding basic initialization beginning of next week

waquino
2020-03-29 21:24
has joined #pact-js

kaz.udesh
2020-03-30 03:39
has joined #pact-js

davidpihlaja
2020-03-30 19:09
has joined #pact-js

matt.fellows
2020-03-31 01:16
@tjones FYI I made some changes to the travis release processes last night, in order to get around the release problems. I tested a publish on a branch and it worked, but just a heads up in case there is an issue next time we release.

matt.fellows
2020-03-31 01:17
It now uses the multi-stage build to do the release step - so will _only_ release if the initial builds are all successful

tjones
2020-03-31 01:49
Nice work! Thanks for doing the legwork!

matt.fellows
2020-03-31 01:56
np

matt.fellows
2020-03-31 01:56
just had to be done

matt.fellows
2020-03-31 01:56
and it annoyed me so much that I passed the critical threshold

tjones
2020-03-31 02:00
DDD, or Derailment Driven Development

matt.fellows
2020-03-31 02:00
:smile:

ramspotla
2020-03-31 02:39
has joined #pact-js

ramspotla
2020-03-31 02:40
Hi There - I was wondering does anyone encounter below issue:

ramspotla
2020-03-31 02:40
?matchingRules?: { ?$.body.id?: { ?match?: ?regex?, ?regex?: ?^[0-9a-fA-F]+$? }

ramspotla
2020-03-31 02:40
I am using above matching rules but pact provider couldn?t match hexadecimal string

ramspotla
2020-03-31 02:41
* Expected ?5e82a81d8ffec3918330b305? but got ?5e82acc17d545aaf740e5591" at $.id

matt.fellows
2020-03-31 02:42
(FYI please format your code blocks using backticks to aid in readability)

matt.fellows
2020-03-31 02:42
Can you please share the full pact file and any logs?

ramspotla
2020-03-31 02:42
Ok sure

matt.fellows
2020-03-31 02:42
are both the consumers and providers using JS?

ramspotla
2020-03-31 02:42
`?matchingRules?: { ?$.body.id?: { ?match?: ?regex?, ?regex?: ?^[0-9a-fA-F]+$? }`

matt.fellows
2020-03-31 02:43
(triple backticks either side, or use the code block formatting option)

ramspotla
2020-03-31 02:44
```"matchingRules": { "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" }``` Yes both provider and consumer using JS

ramspotla
2020-03-31 02:50
```{ "consumer": { "name": "Client" }, "provider": { "name": "someservie" }, "interactions": [{ "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers/getengineer", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [{ "name": "Ram", "practice": "Test", "id": "5e8280694c55aa3b3263fe9a" }], "matchingRules": { "$.body[0].id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } }, { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers/addengineer", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": "5e82a81d8ffec3918330b305" }, "matchingRules": { "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } } ], "metadata": { "pactSpecification": { "version": "4.0.0" } } }```

ramspotla
2020-03-31 02:51
When running against provider I am seeing ?* Expected ?5e82a81d8ffec3918330b305? but got ?5e82af6fbc760fb6f185128d? at $.id?

matt.fellows
2020-03-31 02:52
@prabhuramchennai just as an aside, your resource model looks very non-RESTful

matt.fellows
2020-03-31 02:52
e.g. /engineers/addengineer should simply be a `POST` to `/engineers/`

matt.fellows
2020-03-31 02:53
e.g. /engineers/getengineer should simply be a `GET` to `/engineers/`

matt.fellows
2020-03-31 02:53
the resource is `engineer` and you?ve pluralised it :white_check_mark:

matt.fellows
2020-03-31 02:53
but the suffixes make it look like an RPC

matt.fellows
2020-03-31 02:53
How have you gotten pact specification `4.0.0`? That is not a valid specification for JS

ramspotla
2020-03-31 02:54
Yeah Matt . Just trying out tool

matt.fellows
2020-03-31 02:54
did you make the pact by hand?

matt.fellows
2020-03-31 02:54
bbl

ramspotla
2020-03-31 02:55
I was using pact:3.0.0 . Just changed to 4.0.0 see whether I am getting same issue

ramspotla
2020-03-31 02:55
Even with 3.0.0 I am seeing 3.0.o

matt.fellows
2020-03-31 02:56
How did you generate the pact? Is it JS on the consumer and provider?

matt.fellows
2020-03-31 02:56
Or did you write the pact by hand?

matt.fellows
2020-03-31 02:56
I think you want 2.0.0 anyway

ramspotla
2020-03-31 02:57
Tool successfully generated pact file.

ramspotla
2020-03-31 03:03
```I, [2020-03-31T14:01:36.146943 #49127] INFO -- : Registered expected interaction GET /engineers/getengineer D, [2020-03-31T14:01:36.147192 #49127] DEBUG -- : { "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers/getengineer", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": "Ram", "practice": "Test", "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] }, "metadata": null } I, [2020-03-31T14:01:36.153500 #49127] INFO -- : Received request GET /engineers/getengineer D, [2020-03-31T14:01:36.153615 #49127] DEBUG -- : { "path": "/engineers/getengineer", "query": "", "method": "get", "headers": { "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-03-31T14:01:36.153848 #49127] INFO -- : Found matching response for GET /engineers/getengineer D, [2020-03-31T14:01:36.153949 #49127] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": "Ram", "practice": "Test", "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] } I, [2020-03-31T14:01:36.160484 #49127] INFO -- : Verifying - interactions matched I, [2020-03-31T14:01:36.163947 #49127] INFO -- : Cleared interactions I, [2020-03-31T14:01:36.168877 #49127] INFO -- : Registered expected interaction POST /engineers/addengineer D, [2020-03-31T14:01:36.169028 #49127] DEBUG -- : { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers/addengineer", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } }, "metadata": null } I, [2020-03-31T14:01:36.173080 #49127] INFO -- : Received request POST /engineers/addengineer D, [2020-03-31T14:01:36.173206 #49127] DEBUG -- : { "path": "/engineers/addengineer", "query": "", "method": "post", "body": { "name": "New Engineer", "practice": "Dev" }, "headers": { "Content-Length": "40", "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-03-31T14:01:36.173392 #49127] INFO -- : Found matching response for POST /engineers/addengineer D, [2020-03-31T14:01:36.173498 #49127] DEBUG -- : { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } } I, [2020-03-31T14:01:36.177172 #49127] INFO -- : Verifying - interactions matched I, [2020-03-31T14:01:36.180264 #49127] INFO -- : Cleared interactions I, [2020-03-31T14:01:36.183980 #49127] INFO -- : Writing pact for EngineerService to /Users/ram/practice/pact-example/consumer-driven/consumer/pacts/client-engineerservice.json```

ramspotla
2020-03-31 03:04
```{ "consumer": { "name": "Client" }, "provider": { "name": "EngineerService" }, "interactions": [ { "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers/getengineer", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": "Ram", "practice": "Test", "id": "5e8280694c55aa3b3263fe9a" } ], "matchingRules": { "$.body[0].id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } }, { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers/addengineer", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": "5e82a81d8ffec3918330b305" }, "matchingRules": { "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

ramspotla
2020-03-31 03:05
as you can see pact file generated successfully by pact

matt.fellows
2020-03-31 03:12
Thanks Can you please share the actual response from the provider and also the verifier output

ramspotla
2020-03-31 03:16
After you pointed out I changed the version from spec 4.0.0 to 2.0.0.

ramspotla
2020-03-31 03:17
It worked .

ramspotla
2020-03-31 03:17
So what does that mean Matt?

ramspotla
2020-03-31 03:18
Can I find somewhere which version and which matchers should I use for JS?

matt.fellows
2020-03-31 03:56
How did you set it in the first place?

matt.fellows
2020-03-31 03:57
Just leave it as the default

matt.fellows
2020-03-31 03:59
Also, what made you think to change it? perhaps we have some misleading documentation

matt.fellows
2020-03-31 03:59
Also see feature support https://docs.pact.io/feature_support

tjones
2020-04-01 04:14
Hi @ramspotla, you can find the matcher documentation here: https://github.com/pact-foundation/pact-js#match-common-formats, with an example test below it. In your case, it looks like you?d want: ```provider.addInteraction({ state: "add a engineer", uponReceiving: "a request to post a engineer", withRequest: { method: "POST", path: "/engineers/addengineer", headers: { "Content-Type": "application/json; charset=utf-8" }, }, willRespondWith: { status: 201, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { name: "New Engineer", practice: "Dev", id: Matchers.term({matcher: "^[0-9a-fA-F]+$", generate: "5e82a81d8ffec3918330b305"}), }, }, })```

tjones
2020-04-01 04:17
I agree with matt?s comments about the API design, btw. Also, it looks like you might not be using `state` correctly - have a read of https://docs.pact.io/getting_started/provider_states

ramspotla
2020-04-01 04:17
Hi Tim - thank you . Initially I used term function . It pact was not able to match the hexa string.

ramspotla
2020-04-01 04:17
so now I am using hexadecimal function from Matchers

ramspotla
2020-04-01 04:17
it worked

matt.fellows
2020-04-01 04:18
The reason why I wanted to see your code and what the API actually was Ram, is that I see a potential issue

ramspotla
2020-04-01 04:19
Yes I am not using state. But I am using Jest hooks to get the data state

ramspotla
2020-04-01 04:19
I am directly connecting to db and getting the state what I wanted.

matt.fellows
2020-04-01 04:19
In the `a request to retrieve engineers list`interaction, your matcher is _only_ matching on the `id` of the _first_ item in the list that comes back. So this indicates you?re not using a `eachLike` matcher, and are instead will be matching on an array with exactly 1 item, where the `id` must be a hexadecimal string. Almost certainly, this is not what you want

ramspotla
2020-04-01 04:19
It?s all good now. Working

ramspotla
2020-04-01 04:20
I was trying all other matchers see how they work

ramspotla
2020-04-01 04:20
I tried term, like

matt.fellows
2020-04-01 04:21
@tjones what you do think about Pact JS warning in the situation where there is a matcher applied to an attribute that is within an object list (it would have to support nesting). Because 9 times out of 10, this is probably not what you want

ramspotla
2020-04-01 04:21
But term not working though pact created match regex properly

matt.fellows
2020-04-01 04:21
can you please share your code? That will help

ramspotla
2020-04-01 04:22
sure

ramspotla
2020-04-01 04:22
when I used term : term({matcher: ?^[0-9a-fA-F]+$?, generate: ?5e82a81d8ffec3918330b305?}

tjones
2020-04-01 04:23
Can you share the whole test, please?

ramspotla
2020-04-01 04:23
but pact not able to match hexa string.

ramspotla
2020-04-01 04:23
after that I tried to use hexadecimal then it?s ok

ramspotla
2020-04-01 04:23
I will Tim

ramspotla
2020-04-01 04:24
give me couple of minutes pls

ramspotla
2020-04-01 04:27
Other small issue I am encountering is

ramspotla
2020-04-01 04:27
my api sends status code 201 and also pact files also has the same status code

ramspotla
2020-04-01 04:29
But when I am trying with provider pact it?s complaining status code 200. I was wondering what could be that causing that issue

matt.fellows
2020-04-01 04:30
can you please share your code?

matt.fellows
2020-04-01 04:31
If the pact has `201` in it, and the provider does not return a `201` it will fail. So either a) your provider is not returning a `201` or there is a configuration issue somewhere

ramspotla
2020-04-01 04:32
what exactly you wann see. log file or pact file or both consumer test?

matt.fellows
2020-04-01 04:32
as much as you have will help us help you!

ramspotla
2020-04-01 04:32
```{ "consumer": { "name": "Client" }, "provider": { "name": "EngineerService" }, "interactions": [{ "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [{ "name": "Ram", "practice": "Test", "id": "5e8280694c55aa3b3263fe9a" }], "matchingRules": { "$.body[0].name": { "match": "type" }, "$.body[0].practice": { "match": "type" }, "$.body[0].id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } }, { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": "5e82a81d8ffec3918330b305" }, "matchingRules": { "$.body.name": { "match": "type" }, "$.body.practice": { "match": "type" }, "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

tjones
2020-04-01 04:32
Can you send the consumer test please?

ramspotla
2020-04-01 04:32
Yep

ramspotla
2020-04-01 04:33
```require('dotenv').config() const request = require('supertest') const provider = require('../expectation/provider') const interactions = require('../expectation/interactions') const serverAddress = `http://localhost:${process.env.CLIENT_PORT}` const baseUrl = '/engineers' const consumerClient = request(`${serverAddress}`) describe('api testing', () => { jest.setTimeout(60000) beforeAll(async () => { await provider.setup() }) afterAll(async () => { await provider.finalize() }) afterEach(async () => { await provider.verify() }) test('get all engineers', async () => { await provider.addInteraction(interactions.getEngineersList) const res = await consumerClient .get(`${baseUrl}`) .set('Content-Type', 'application/json; charset=utf-8') expect(JSON.parse(res.text)).toEqual([ { name: 'Ram', practice: 'Test', id: '5e8280694c55aa3b3263fe9a' } ]) }) test('post a engineer', async () => { await provider.addInteraction(interactions.createEngineer) const payload = { name: 'New Engineer', practice: 'Dev' } const res = await consumerClient .post(`${baseUrl}`) .set('Content-Type', 'application/json; charset=utf-8') .send(payload) .expect(201) expect(JSON.parse(res.text)).toEqual({ name: 'New Engineer', practice: 'Dev', id: '5e82a81d8ffec3918330b305' }) }) })```

matt.fellows
2020-04-01 04:35
is `process.env.CLIENT_PORT`pointing at the pact mock server port?

ramspotla
2020-04-01 04:38
Yes Matt

ramspotla
2020-04-01 04:38
```const opts = { consumer: 'Client', provider: 'EngineerService', port: parseInt(process.env.CLIENT_PORT), log: path.resolve(__dirname, '../../logs'), loglevel: 'ERROR', dir: path.resolve(__dirname, '../pacts'), spec: 2.0 }```

matt.fellows
2020-04-01 04:41
can you please also share the expectations file and the logs?

ramspotla
2020-04-01 04:43
I be back in 10 minutes . I got to go. Thank you Matt and Tim

matt.fellows
2020-04-01 04:44
np

ramspotla
2020-04-01 04:58
Hi

ramspotla
2020-04-01 05:00
```I, [2020-04-01T15:26:28.556393 #47039] INFO -- : Registered expected interaction GET /engineers D, [2020-04-01T15:26:28.556706 #47039] DEBUG -- : { "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": { "json_class": "Pact::SomethingLike", "contents": "Ram" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Test" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] }, "metadata": null } I, [2020-04-01T15:26:28.563401 #47039] INFO -- : Received request GET /engineers D, [2020-04-01T15:26:28.563511 #47039] DEBUG -- : { "path": "/engineers", "query": "", "method": "get", "headers": { "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-04-01T15:26:28.563752 #47039] INFO -- : Found matching response for GET /engineers D, [2020-04-01T15:26:28.563872 #47039] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": { "json_class": "Pact::SomethingLike", "contents": "Ram" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Test" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] } I, [2020-04-01T15:26:28.570494 #47039] INFO -- : Verifying - interactions matched I, [2020-04-01T15:26:28.573592 #47039] INFO -- : Cleared interactions I, [2020-04-01T15:26:28.577693 #47039] INFO -- : Registered expected interaction POST /engineers D, [2020-04-01T15:26:28.577852 #47039] DEBUG -- : { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": { "json_class": "Pact::SomethingLike", "contents": "New Engineer" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Dev" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } }, "metadata": null } I, [2020-04-01T15:26:28.581590 #47039] INFO -- : Received request POST /engineers D, [2020-04-01T15:26:28.581708 #47039] DEBUG -- : { "path": "/engineers", "query": "", "method": "post", "body": { "name": "New Engineer", "practice": "Dev" }, "headers": { "Content-Length": "40", "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-04-01T15:26:28.581855 #47039] INFO -- : Found matching response for POST /engineers D, [2020-04-01T15:26:28.581967 #47039] DEBUG -- : { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": { "json_class": "Pact::SomethingLike", "contents": "New Engineer" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Dev" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } } I, [2020-04-01T15:26:28.585538 #47039] INFO -- : Verifying - interactions matched I, [2020-04-01T15:26:28.588517 #47039] INFO -- : Cleared interactions I, [2020-04-01T15:26:28.591790 #47039] INFO -- : Writing pact for EngineerService to /Users/ram/practice/pact-example/consumer-driven/consumer/pacts/client-engineerservice.json```

ramspotla
2020-04-01 05:00
see the proivder logs: sending 201

ramspotla
2020-04-01 05:00
POST /engineers 201 16.618 ms - 64

ramspotla
2020-04-01 05:03
```'use strict' const { Matchers } = require('@pact-foundation/pact') const { eachLike, like, term, hexadecimal } = Matchers const baseUrl = '/engineers' const ENGINEERS_GET_BODY = [ { name: like('Ram'), practice: like('Test'), id: hexadecimal('5e8280694c55aa3b3263fe9a') } ] const ENGINEER_POST_PAYLOAD = { name: 'New Engineer', practice: 'Dev' } const ENGINEER_RES_PAYLOAD = { name: like('New Engineer'), practice: like('Dev'), id: hexadecimal('5e82a81d8ffec3918330b305') } module.exports = { getEngineersList: { state: 'engineers list', uponReceiving: 'a request to retrieve engineers list', withRequest: { method: 'GET', path: `${baseUrl}`, headers: { 'Content-Type': 'application/json; charset=utf-8' } }, willRespondWith: { status: 200, body: ENGINEERS_GET_BODY, headers: { 'Content-Type': 'application/json; charset=utf-8' } } }, createEngineer: { state: 'add a engineer', uponReceiving: 'a request to post a engineer', withRequest: { method: 'POST', path: `${baseUrl}`, headers: { 'Content-Type': 'application/json; charset=utf-8' }, body: ENGINEER_POST_PAYLOAD }, willRespondWith: { status: 201, body: ENGINEER_RES_PAYLOAD, headers: { 'Content-Type': 'application/json; charset=utf-8' } } } }```

matt.fellows
2020-04-01 07:21
I don't see any provider logs. Is the problem with the consumer test or the provider test?

matt.fellows
2020-04-01 07:22
Can you show what the actual problem is?

cesar.lopes
2020-04-01 13:58
Hi, any way I can log the verifier requests? I?m trying to validate a POST method, but the body is not being passed on the request: the contract: ```{ "consumer": { "name": "EatFruits" }, "provider": { "name": "Fruits" }, "interactions": [ { "description": "a fruit", "providerState": "when I add a fruit", "request": { "method": "POST", "path": "/api/fruits", "headers": { "Accept": "application/json" }, "body": { "name": "Fruit_1", "price": 1.2, "calories": 120 } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "message": "New fruit created!", "data": { "_id": { "generate": "5e847e5c5ba97d17dcdb7a51", "matcher": "([0-9a-f]+)" }, "create_date": { "generate": "2020-04-01T11:43:24.950Z", "matcher": "(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2})\\:(\\d{2})\\:(\\d{2}).(\\d{3})Z" }, "name": "Fruit_1", "price": 1.2, "calories": 120, "__v": 0 } }, "matchingRules": { "$.body.data._id": { "match": "type" }, "$.body.data.create_date": { "match": "type" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

cesar.lopes
2020-04-01 14:10
wrong request header :disappointed:

cesar.lopes
2020-04-01 14:10
```headers: { 'Content-Type': 'application/json;charset=utf-8', },```

sacharya_pact
2020-04-02 05:38
has joined #pact-js

lbraymusso
2020-04-02 05:40
has joined #pact-js

ramspotla
2020-04-03 02:44
problem is : pact provider fails due to status code not matching

cesar.lopes
2020-04-03 08:10
yes @ramspotla, because I define wrong Content-type for request headers, and the request body was not passed.

safiyya
2020-04-03 14:07
has joined #pact-js

ramspotla
2020-04-05 00:10
Thank you I try that. Sorry my bad copy and paste

ramspotla
2020-04-05 00:11
error

cesar.lopes
2020-04-05 00:12
?

mcruzdrake
2020-04-05 16:30
has joined #pact-js

christopher.richard
2020-04-06 18:22
has joined #pact-js

christopher.richard
2020-04-06 18:38
Seeing something weird with an interaction I'm adding. In my logs I can see I've added the interaction: ```[2020-04-06T14:02:02.378142 #7624] INFO -- : Registered expected interaction GET /v1/users/402/memberships?cancelled=false``` But then it seems to fail when the request is made: ```[2020-04-06T14:02:02.384429 #7624] ERROR -- : No matching interaction found for GET /v1/users/402/memberships?cancelled=false``` It seems to not like the QS, but I've used the same structure for other requests: ```[2020-04-06T14:02:02.359280 #7624] INFO -- : Registered expected interaction GET /v1/users/401/memberships?expired=false [2020-04-06T14:02:02.364947 #7624] INFO -- : Found matching response for GET /v1/users/401/memberships?expired=false```

christopher.richard
2020-04-06 18:39
Can anyone see something I'm not seeing?

christopher.richard
2020-04-06 19:13
Found it. turns out `false != 'false'`

matt.fellows
2020-04-06 22:12
:smile:

matt.fellows
2020-04-06 22:12
Query strings are all _strings_ but it?s easy to forget

abubics
2020-04-06 23:27
sounds like something to add a warning for? If there are any non-strings in query defs :thinking_face:

matt.fellows
2020-04-06 23:36
Yep good idea. I'll raise an issue for it shortly

tjones
2020-04-07 00:58
We could also get the broker to provide hints when the log prints the same string twice (usually this is headers)

tjones
2020-04-07 00:59
it?s annoying to have situations that result in `you didn't request "GET /foo/bar"`, and `I expected "GET /foo/bar"`

abubics
2020-04-07 01:05
ah, very similar symptoms for other attributes . . .

christopher.richard
2020-04-07 13:02
Seems to me the `query` attr in a new interaction's `withRequest` object should validate against non-strings?

matt.fellows
2020-04-07 13:12
Yep, that?s the idea

matt.fellows
2020-04-07 13:12
It?s currently enforced by typescript, but that?s not sufficient. I?ll add

cesar.lopes
2020-04-07 14:04
hello, any way I can use a pact interaction and don?t create a contract for it?

matt.fellows
2020-04-07 21:35
Can you please elaborate on what you need Cesar?

cesar.lopes
2020-04-08 08:28
Hello Matt, I?m trying to replace all jest.mock from units tests in a project with PACT :heart_eyes_cat: We have some mock unit tests that are not applicable on provider, Ex: I get a wrong body response and a 200 status code

cesar.lopes
2020-04-08 08:29
I cannot test that against the provider, for now I just adding those contracts to a dummy file called tobe-discarded.json

cesar.lopes
2020-04-08 08:29
And I neve user that contracts for validations on provider

cesar.lopes
2020-04-08 08:30
my question is, Is any way I can use pact for mock, but dont generate those contracts?

anguyen0815
2020-04-08 22:15
has joined #pact-js

rbenbolton
2020-04-09 17:48
Hey everyone, I?m new to the pact-js side of things and trying to set up a simple login test that returns a jwt token. I?m trying to wrap the expected response matcher with term, but I?m getting a strange mismatch between Expected and Received. Here?s the test results and I?ll include my code:

rbenbolton
2020-04-09 17:49
I don?t know why it posted the code snippet three times ?

rbenbolton
2020-04-09 21:06
I?ve got it pinned down to the regex matcher. I know it?s not in the right place. Just can?t seem to figure out how it should look.

rbenbolton
2020-04-09 23:27
Well, I?ve made some progress, I think. I updated the matcher and regex, which I realized was wrong. I changed it to: ```body: { data: term({ matcher: /^[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+\.?[A-Za-z0-9_.+\/=-]*$/, generate: "eyJhbGciOiJSUzI1NiIsImtpZCI6ImQtMyIsInR5cCI6IkpXVCJ9.eyJBQ0xTIjp7IjY3MDNkZjcxLWJmODMtNDU1ZC05ZTg4LTVlNDI2ODE4M2Q5ZCI6WzIwLDIxLDMwLDQwMCw0MDEsNDAyLDQwMyw0MDQsNDA3LDQwOF19LCJleHAiOjE1ODY0NzkyMDQsImV4cEJ1ZmZlciI6MTU4NjUwODAwNCwiaWF0IjoxNTg2NDY0ODA0LCJqdGkiOiJhODE1NDY3Ni00Njk5LTRhMTgtOWUyOS1lZjI0YzUxY2QxZjMiLCJ0eXBlIjoicHJhY3RpY2UiLCJ1c2VyX2lkIjoiM2Y3OGJhNGQtZDg3Yy00MmJjLTkzMDItMTRkMzY2Mjc1MzQyIiwidXNlcm5hbWUiOiJkZXYtYXV0aC1tb25pdG9yLTU2MjI2ODQ1NTJAYXNkZi5jb20ifQ.6QjJAmmHv2vCP0mo7JjhAz1iwhMC-Xjdu9Ag0nxxx9-DBMCns-jK1cybRR0_2M5zwGTJkASU_a13-aRS3COiM4NLZcuphMWSBAARHpEBJFacgrGHOFnFFnJzZybERwaW1ftqft6gaITS6tQO_mP4I7oVRgyvIpdU-qgMmNICfixWjRD4LkHY2E4B4WZazbw77SQHrrnToE3p6D6WrSeFY3SmP3uJRGe1muMSJc4sioSdkUHXMeZjEU8wdvjznErQD1uxZoAB5FOnth20CvhgrNSWpb4KpX1KZEtNJeavQGEFVuvktBSdx5yDcbrEsbMFeK22f1RglfoVvIkdTz_yVg" }) }``` But, now I?m getting an error on `term` that says, `TypeError: matcher.replace is not a function`

komeershettyvinod
2020-04-10 05:26
has joined #pact-js

komeershettyvinod
2020-04-10 06:19
Hi

komeershettyvinod
2020-04-10 06:20
I am seeing popsicle error (unable to connect) and pact server is not running up, can any one of you please help


tjones
2020-04-10 06:21
There?s a subtlety here, for which we should probably improve the error message - the `matcher` needs to be a string that contains a Ruby regular expression, not a Javascript regex object

tjones
2020-04-10 06:28
In your other snippet, the problem (which you probably found) was that `expect(response.data).toEqual(loginResponse)` is passed the pact expectation, including the matchers - it needs to be passed the object that you expect to be returned from the API

tjones
2020-04-10 06:30
It?s hard to help with just the error - could you tell us more about the test setup. What happens when you try to start the server?

komeershettyvinod
2020-04-10 08:38
I was trying to run a basic test with angular 7 application. Below are my ```"@pact-foundation/karma-pact": "^2.2.0", "@pact-foundation/pact-node": "^10.2.1", "@pact-foundation/pact-web": "^9.5.0",``` Node version -12.

tjones
2020-04-10 09:44
Could you post the test, please?

komeershettyvinod
2020-04-10 10:46
My test -- ```import { TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; import { Matchers, PactWeb } from '@pact-foundation/pact-web'; import { UserService } from '@app/main/forecast-runs/components/estimate-creation/user.service'; import { User } from '@app/main/forecast-runs/components/estimate-creation/user'; import { Pact } from '@pact-foundation/pact-web/httpPact'; describe('UserServicePact', () => { let provider; // Setup Pact mock server for this service beforeAll(async () => { provider = await new PactWeb({ consumer: 'ui-karma', provider: 'userservice', host: '127.0.0.1', port: 9008 }); // required for slower CI environments await new Promise(resolve => setTimeout(resolve, 1000)); // Required if run with `singleRun: false` await provider.removeInteractions(); }); // Configure Angular Testbed for this service beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpClientModule ], providers: [ UserService ] }); }); // Verify mock service afterEach(async () => { await provider.verify(); }); // Create contract afterAll(async () => { await provider.finalize(); }); describe('get()', () => { const userId = 1; let expectedUser: User = { firstName: 'Zaphod', lastName: 'Beeblebrox' }; beforeAll(async () => { await provider.addInteraction({ state: `user 1 exists`, uponReceiving: 'a request to GET a user', withRequest: { method: 'GET', path: `/api/users/${userId}` }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedUser) } }); }); it('should get a user', async () => { const userService: UserService = TestBed.get(UserService); await userService.get(userId).toPromise().then(response => { expect(response).toEqual(expectedUser); }); }); }); describe('create()', () => { const expectedUser: User = { firstName: 'Arthur', lastName: 'Dent' }; const createdUserId = 42; beforeAll(async () => { await provider.addInteraction({ state: `provider accepts a new user`, uponReceiving: 'a request to POST a user', withRequest: { method: 'POST', path: '/api/users', body: expectedUser, headers: { 'Content-Type': 'application/json' } }, willRespondWith: { status: 201, body: Matchers.somethingLike({ id: createdUserId }), headers: { 'Content-Type': 'application/json' } } }); }); it('should create a user', async () => { const userService: UserService = TestBed.get(UserService); await userService.create(expectedUser).toPromise().then(response => { expect(response).toEqual(createdUserId); }); }); }); describe('update()', () => { let expectedUser: User = { firstName: 'Zaphod', lastName: 'Beeblebrox' }; beforeAll(async () => { await provider.addInteraction({ state: `user 42 exists`, uponReceiving: 'a request to PUT a user', withRequest: { method: 'PUT', path: '/api/users/42', headers: {'Content-Type': 'application/json'}, body: Matchers.somethingLike(expectedUser) }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedUser) } }); }); it('should update a user', async () => { const userService: UserService = TestBed.get(UserService); await userService.update(expectedUser, 42).toPromise().then(response => { expect(response).toEqual(expectedUser); }); }); }); });```

komeershettyvinod
2020-04-10 10:51
// Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html path = require('path'); module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ require('karma-jasmine'), require('@pact-foundation/karma-pact'), require('karma-chrome-launcher'), require('karma-firefox-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('@angular-devkit/build-angular/plugins/karma'), ], client: { clearContext: false, // leave Jasmine Spec Runner output visible in browser jasmine: { timeoutInterval: 40000 } }, coverageIstanbulReporter: { // dir: require('path').join(__dirname, '../coverage'), reports: ['html', 'lcovonly', 'text-summary'], fixWebpackSourcePaths: true, }, reporters: ['progress', 'kjhtml'], port: 9886, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, pact: [ { cors: true, spec: 3, port: 9008, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), '../../pacts') } ], proxies: { '/api': 'http://localhost:9008/api' } }); };

matt.fellows
2020-04-10 11:42
Thanks for that.

matt.fellows
2020-04-10 11:42
Where did you get `spec: 3` from? Not that I think it will break anything, but it?s not a valid spec version

matt.fellows
2020-04-10 11:43
Does the mock server startup?

matt.fellows
2020-04-10 11:43
can you confirm there is nothing already running on port `9008`?

komeershettyvinod
2020-04-10 13:40
regarding spec 3: I just pasted from the internet

komeershettyvinod
2020-04-10 13:40
and karma is being started but pact did not started up

komeershettyvinod
2020-04-10 13:41
no port 9008 is free

rbenbolton
2020-04-10 14:47
Yes, I realized I had the matchers malformed and removed them from the response as well as in the mock request. However, I?ve had a hard time getting the regex correct. I wonder if there couldn?t be a better example in the https://github.com/pact-foundation/pact-js#match-by-regular-expression of what this should look like? It does say, `The underlying mock service is written in Ruby, so the regular expression must be in a Ruby format, not a Javascript format.` But the example shown is simply this: ```gender: term({ matcher: "F|M", generate: "F", }),``` For the expression I?m trying to match - `/^[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+\.?[A-Za-z0-9_.+\/=-]*$/` , which works on https://rubular.com/, even putting this in quotes still throws an error. Should I provide the leading and trailing `/` as I would in ruby or is that replaced by the quotes? From the error messages, it seems they are required, though they are missing from the README example.

rbenbolton
2020-04-10 16:43
With quotes around it, it seems I need to also provide the escape `\`. After doing that, I?m still getting this error: `Example 'eyJhbGciOiJSUzI1NiIsImtpZ ...' does not match provided regular expression '/^[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+\.?[A-Za-z0-9_.+\/=-]*$/'`. I?ve double-checked the regex with that string on http://rubular.com as well as in ruby code locally. Both say it?s a match. I?m really at a loss here as to why this would be failing.

matt.fellows
2020-04-10 21:40
Any logs suggesting why?

matt.fellows
2020-04-10 21:41
> regarding spec 3: I just pasted from the internet where? It is incorrect and must be fixed



komeershettyvinod
2020-04-12 08:03
However even If i comment out that spec line the result is the same

matt.fellows
2020-04-12 10:13
What does the log file say? Can you please post the terminal output? The pact plugin must not be starting correctly

komeershettyvinod
2020-04-12 11:45
Hi Matt

komeershettyvinod
2020-04-12 11:45
I have attached the log file in the above snippet , can you please revie

komeershettyvinod
2020-04-12 11:45
w

matt.fellows
2020-04-13 13:48
Can you please set the log level to DEBUG in karma

matt.fellows
2020-04-13 13:48
``` // Pact Providers pact: [ { port: 1234, consumer: "KarmaJasmineConsumer", provider: "KarmaJasmineProvider", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }, ],```

matt.fellows
2020-04-13 13:48
e.g. as per above

matt.fellows
2020-04-13 13:48
and then provide the logs?

matt.fellows
2020-04-13 13:49
you should be seeing something like this in the logs

matt.fellows
2020-04-13 13:52
Does anybody here use Nock to test their HTTP clients? If so, do you still use that with Pact or did you replace them?

matt.fellows
2020-04-13 13:52
Would it be useful at all to have a Pact integration with nock?

komeershettyvinod
2020-04-13 14:30
console log

rbenbolton
2020-04-13 14:45
@tjones @matt.fellows Any ideas here?

tjones
2020-04-13 15:32
I think the problem is possibly the slashes at either end of the string- try just providing the regex, from `^` to `@`

tjones
2020-04-13 15:32
(Sorry I missed this before)

rbenbolton
2020-04-13 15:38
Ok, so I removed the slashes, and it works if the token provided in the `willRespondWith` is exactly the same as the token returned by the mock provider. However, if I set those to two different tokens, but they both match the regular expression, the test fails. I would expect to be able to provide two different values here and have the test pass as long as they both match the regular expression. Is that not the case? If not, how do I know then that the regex is working?

matt.fellows
2020-04-13 20:55
Might need some help from @bethskurrie on this one. I recall there being a few peculiarities with the regexing on Ruby.

matt.fellows
2020-04-13 20:55
Ideally, if you could repro it at https://github.com/pact-foundation/pact-ruby-standalone-e2e-example/, that would be really helpful

aaron590
2020-04-14 05:57
has joined #pact-js

aaron590
2020-04-14 06:01
Hello, I'm working on setting up pact-js in my CI Pipeline. I'm getting an error that rake cannot be found and cat Gemfile.lock is not present when I run `jest --testPathPattern .*\.pact\.spec\.js --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile=./pact/pactTestWrapper.js` Everything works locally. Any help would be appreciated. It's in CircleCI. It appears that pact-js depends on pact-node, which relies on some ruby gems.

matt.fellows
2020-04-14 07:11
Hi

matt.fellows
2020-04-14 07:11
So basically, we bundle a traveling Ruby installation in Pact Node with a Ruby app that does a lot of the hard work under the hood

matt.fellows
2020-04-14 07:12
It should be all but hidden from you, however it?s revealing itself to you now - sorry!

matt.fellows
2020-04-14 07:12
I have seen this before, I think

matt.fellows
2020-04-14 07:12
It?s when it?s running in an environment where there are Ruby environment variables already present

matt.fellows
2020-04-14 07:12
e.g. `BUNDLE_APP_CONFIG` . I think if you unset them, it may help, but let me find any related issues

matt.fellows
2020-04-14 07:33
OK was just able to repro the issue locally when that env var is set

matt.fellows
2020-04-14 07:35
found this old issue too

matt.fellows
2020-04-14 07:43
Have just raised a PR to fix this in the standalone library, which would fix it for you. In the meantime, explicitly _unset_ that environment variable in your build, and you should be golden. Apologies. https://github.com/pact-foundation/pact-ruby-standalone/pull/50

aaron590
2020-04-14 14:17
Thanks for the quick reply. `unset BUNDLE_APP_CONFIG && yarn pact:test` solved it. Thank you

matt.fellows
2020-04-14 21:22
:+1:

matt.fellows
2020-04-14 21:22
It will be fixed in the library in the next day or so. Thanks for bringing it to my attention. To be honest, I'm surprised it hasn't shown up before given the popularity of circle!

aaron590
2020-04-14 21:26
I?m assuming most people would choose a node environment for their ui container. Currently my project is small enough that i have my rails back end and react front end in the same repo. That means I?m using a ruby & node container.

matt.fellows
2020-04-14 21:34
ahh, yes, makes sense then

mcruzdrake
2020-04-15 16:12
Hi all, we are using Pact-js and the pact-broker for one of our projects and I am trying to visualize what our CI pipeline would be. Can someone point me to the right direction on how I can use the Pact webhooks to trigger the provider tests when a contract has been published from the consumer? We are using CircleCI. Thanks in advance!

david.tran
2020-04-15 16:27
has joined #pact-js

christopher.richard
2020-04-15 17:25
Hi Marie! not sure if this helps but I found this example useful: https://github.com/pact-foundation/pact_broker/wiki/Webhooks#example-cicd-and-webhook-configuration

matt.fellows
2020-04-15 23:22
That?s the doc Chris, albeit they?ve now moved to https://docs.pact.io/pact_broker/advanced_topics/webhooks

matt.fellows
2020-04-15 23:22
I?ll follow up that, because the old wiki should have been deprecated

akkoubak
2020-04-16 00:33
has joined #pact-js

akkoubak
2020-04-16 00:38
Hello, I am attempting to validate a contract that contains 22 interactions. The provider is run with JEST using the standalone provider. The issue is that the provider times out during execution returning a `Timeout waiting for verification process to complete (PID: 6428)` `at Timeout._onTimeout (node_modules/q/q.js:1846:21).`

matt.fellows
2020-04-16 00:40
Have you tried increasing the test timeout in Jest?

akkoubak
2020-04-16 00:45
Hi Matt, yes I did. I increased by modifying the jest setup file (jest.setTimeout(300000)). I also verified that that JEST is respecting the timeout defined by changing the timeout. Here is my provider test `/* eslint-env jest */` `const { Verifier } = require('@pact-foundation/pact')` `const client = require('../token/getToken')` `require('../../src/index.js')` `describe('Pact Verification', () => {`   `it('validates the expectations of Matching Service', () => {`     `afterEach(() => {`       `process.exit()`     `})`     `const opts = {`       `provider: 'ApolloGateway',`       `logLevel: 'DEBUG',`       `providerBaseUrl: 'http://localhost:4000',`       `requestFilter: async (req, res, next) => {`         `console.log(`           `'Middleware invoked before provider API - injecting Authorization token'`         `)`         `// req.headers["MY_SPECIAL_HEADER"] = "my special value"`         `// e.g. ADD Bearer token`         `const generatedJWT = await client.getJWT()`         `req.headers.authorization = `Bearer ${generatedJWT}``         `next()`       `},`       `// Enables "pending pacts" feature`       `enablePending: true,`       `// Specific Remote pacts (doesn't need to be a broker)`       `pactUrls: ['https://mybroker'],`       `// If you're NOT using Pactflow, use the username/password option as per below`       `// pactBrokerUsername: "",`       `// pactBrokerPassword: "",`       `pactBrokerToken: '',`       `publishVerificationResult: true,`       `providerVersion: '1.0.0'`     `}`     `return new Verifier(opts).verifyProvider().then(output => {`       `console.log('Pact Verification Complete!')`       `console.log(output)`       `process.exit()`     `})`   `})` `})` and here is my failure on the provider side

akkoubak
2020-04-16 00:49
BTW, the provider seems to timeout at 30 seconds


matt.fellows
2020-04-16 00:59
It defaults to `30000` (30s)

akkoubak
2020-04-16 01:02
Worked like magic. Thanks Matt!!

matt.fellows
2020-04-16 01:02
:thumbsup:

matt.fellows
2020-04-16 01:02
awesome

yka
2020-04-16 07:01
has joined #pact-js

yka
2020-04-16 07:07
Hi, Is there anyone who can assist finalising PactJS implementation on Angular? I got multiple micro-service instances to write pacts for and I can't work out how to do this without passing consumer to PactWeb rather than just defining multiple pacts in my karma config. So far the way I have done this is by having multiple pact declarations in karma conf to start the mock servers each having different ports of course, then I defined proxies for my endpoints to point to the corresponding pact port, and finally declaring an empty PactWeb provider in my pact test. This worked fine for one microservice, however, when I implemented the next microservice I cannot do an empty PactWeb provider declaration in pact test. Have I gone off track of how it should be implemented?

matt.fellows
2020-04-16 07:09
:wave:

matt.fellows
2020-04-16 07:09
so my first question - can you do this without Karma/Jasmine? Because that?s the source of much pain (e.g. can you use a Node JS framework)

matt.fellows
2020-04-16 07:10
my next question - can you just specify the `port` in the different `PactWeb` instances? That should pass through to the correct back end mock

yka
2020-04-16 07:14
Offf, just be aware that I am just switching from Java so my knowledge is bit iffy... To answer your question - we probably can(?), this is a greenfield project at an early stage so got lots of flexibility - would you say ditching this karma setup would be best then? Type safety doesn't allow not defining PactOptions without consumer and provider. My concern really comes from the planned deprecation of this. It is 3 extra lines of code so not too much skin off our backs.

matt.fellows
2020-04-16 07:14
ah, fair enough

matt.fellows
2020-04-16 07:15
Look, personally, I prefer to avoid Karma because it runs in the browser - you shouldn?t be testing anything that has a dependency on a browser (except at a low level, the XMLHttpRequest that makes the actual http calls - but Ng abstracts that anyway, I think [confirm with an ng expert])

matt.fellows
2020-04-16 07:16
All you should be testing in your Pact tests, is the client/collaborators that make the HTTP calls - this is a different concern to the UI components, which probably need a browser

matt.fellows
2020-04-16 07:17
But, I understand the TS options. We?ll remove the fields in the next major release. Perhaps I should just make that change now, and avoid your pain?

yka
2020-04-16 07:21
Thanks Matt, that does clear things up. I just started looking into testing yesterday so all new to me on that front. Are you aware of any testing frameworks that I should go for - just a name drop will do to start me off on my search :) If it is not too much trouble adding those two question marks then that would be very helpful :slightly_smiling_face:

matt.fellows
2020-04-16 07:34
Common test fameworks in JS land: Jest, Mocha, Ava. I?d stick with Jest/mocha, because they are the most common. But I?ll caveat that with Angular may have different preferences, and you may want to align where possible to reduce friction for developers on the team

matt.fellows
2020-04-16 07:36
Looking at the docs (https://angular.io/guide/testing) probably sticking within Jasmine/Karma is the way to go. See PR above, i?ll get that in tomorrow (ideally) and a new release out

yka
2020-04-16 07:37
Thank you Matt, you've been most helpful and not even mentioning how quick!

matt.fellows
2020-04-16 07:40
You?re welcome

matt.fellows
2020-04-16 07:51
@tjones FYI context for #432

tjones
2020-04-16 07:57
Awesome, thanks! I used the merge button to indicate my positive review

matt.fellows
2020-04-16 07:57
this works!

matt.fellows
2020-04-16 07:58
`v9.9.4` is on the way?

tjones
2020-04-16 07:58
@yka I?ve been thinking about writing a blog post or documentation article to illustrate how pact works best with UI frameworks in JS - would this be something you would have found useful?

tjones
2020-04-16 07:58
#teamwork!

yka
2020-04-16 08:22
Hi @tjones, Yeah I think that would've been helpful. It did take me some time to wrap my head around things and collate the information I needed. Also many resources I came across were old so it obviously made me question their integrity.

mcruzdrake
2020-04-16 08:37
Thanks both. Will use this as reference

tjones
2020-04-16 08:54
Thanks, this is very helpful! If you have the time, would you mind linking me to the old docs you found questionable? Maybe we can update or move them to increase confidence

yka
2020-04-16 09:02
Hi Matt, I've started looking into this and I am being a bit dim here. I am looking at the diff now and getting a bit confused as to how to implement this. :grimacing:

yka
2020-04-16 09:05
Previously i used the constructor and that uses a PactOptions interface.

matt.fellows
2020-04-16 09:25
The net result should be the exact same interface, but those two options are now gone completely (I couldn't use the same type because it shares the types with the main pact interface)

yka
2020-04-16 13:10
I wish that would be possible, I went through various resources yesterday spent a whole day through trial and error so it is very hard to think or find in my history anything in particular. Also some of the material I was referring to were outside of the foundation's resources. Sorry I could not give you an exact answer :disappointed:

joao.salles
2020-04-17 09:37
has joined #pact-js

safiyya
2020-04-17 13:31
I?m trying to verify a async contract published on Pactflow and following the instructions here https://github.com/pact-foundation/pact-js#provider-producer. I dont seem to be able to add a `pactBrokerToken` prop to the `MessageProviderPact` and my calls to our pactflow address all come back as 401. Is there another way to use Pactflow in async testing? I couldnt find anything online related to my use case

matt.fellows
2020-04-17 13:47
Would you mind filing a bug please? May be a typing issue

safiyya
2020-04-17 14:56
Sure, will do

darshan
2020-04-20 16:34
has joined #pact-js

yka
2020-04-22 13:30
Hi, Got an angular project here using karma as test framework. Is there any way around proxying each request? If I remove proxy and use the service call to full url (+correct port for pact) my pact json generates but my test fails.

james.salamon
2020-04-22 13:40
has joined #pact-js

yka
2020-04-22 15:26
Nevermind, I was being a bit dim in how I set up my proxies :grimacing:

corey
2020-04-23 15:17
has joined #pact-js

yosevuk
2020-04-23 19:55
Hello, I'm having trouble trying to address this error in a consumer contract test and I think I have a knowledge gap. How come the second query param isn't recognized? Can anyone help? Error: `Actual interactions do not match expected interactions for mock MockService.` Interaction: ```const page = { withRequest: { method: 'GET', path: '/path/page/xx', query: 'param1=param1_Value&requestType=page', headers: { apiKey: '123', }, }, willRespondWith: { status: 200, headers: headerExpectations, body: pageExpectations, }, };``` Log: ```No matching interaction found for GET /path/page/xx?param1=param1_Value Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "query": { - "requestType": [ - "page", - ] } } Description of differences -------------------------------------- * Could not find key "requestType" (keys present are: param1) at $.query ```

yosevuk
2020-04-23 20:01
Please disregard, it was just an error due to a local environment variable when I ran the tests :blush:

shurik
2020-04-24 14:17
has joined #pact-js

shurik
2020-04-24 14:42
Do you guys know any good example of open-source React or Angular projects which are using all power of pacts to enforce API provider?

matt.fellows
2020-04-25 01:13
Are you just looking for examples or case studies? There are lots of articles out there on both topics

shurik
2020-04-27 17:15
I was looking for some examples in real life projects. Want to know who is using it.

matt.fellows
2020-04-27 21:26
I'll try to update our media links. There's so many we kind of stopped.

shurik
2020-04-28 16:42
ok I'll be waiting, thanks in advance

stephen.rhodes
2020-04-29 18:21
has joined #pact-js

leonardo.k.magalhaes
2020-04-29 21:33
has joined #pact-js

brendan.j.donegan
2020-04-29 21:40
has joined #pact-js

baquinteros
2020-04-30 01:06
has joined #pact-js

baquinteros
2020-04-30 01:13
Hi guys, I'd like to add the cors flag in PactOptions for the jest-pact project. I've raised an issue. https://github.com/pact-foundation/jest-pact/issues/187 I've added it locally and it works.

matt.fellows
2020-04-30 01:25
Thanks for raising, Ben. I?ve just responded with my thoughts

dan.h.lee329
2020-05-02 01:54
has joined #pact-js

sen.rudrappa
2020-05-02 06:52
has joined #pact-js

krishnam.misc
2020-05-04 07:40
has joined #pact-js

krishnam.misc
2020-05-04 07:42
I see below warning when the default tests are run in fresh clone version for _jest_ tests WARN: Ignoring unsupported matching rules {"min"=>1} for path $['query']['catId'][] [2020-05-04T07:36:54.060Z] ERROR: pact-node@9.0.7/22480 on LTIN114925:     Pact Binary Error:     WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['query']['catId'][][*]* [2020-05-04T07:36:54.063Z]  INFO: pact@9.2.1/22480 on LTIN114925: Pact File Written [2020-05-04T07:36:54.064Z]  INFO: pact-node@9.0.7/22480 on LTIN114925: Removing Pact with PID: 7004  PASS  __tests__/index.spec.js (5.023s) Test Suites: 3 passed, 3 total Tests:       4 passed, 4 total Snapshots:   0 total

tjones
2020-05-04 07:43
I noticed this yesterday when updating the tests - I think the warning is indicating a bug (without any negative impact) in using matchers in query strings

krishnam.misc
2020-05-04 07:43
Okay, thanks for the update


krishnam.misc
2020-05-04 07:44
ERROR: The process "23412" not found. [2020-05-04T04:55:16.578Z] ERROR: pact-node@9.0.7/12924 on LTIN114925:     Pact Binary Error: C:/ComCast/TestCafe/ContractTesting/pact-js-master/pact-js-master/examples/jest/node_modules/@pact-foundation/pact-node/standalone/win32-1.70.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': cannot load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError) This occurs when the end user is running his tests from a workspace that has lengthy breadcrumb

krishnam.misc
2020-05-04 07:45
When I was asked to move to shorter folder name, it works. We may also need to fix this?

tjones
2020-05-04 07:45
This is a limitation of the windows operating system.

krishnam.misc
2020-05-04 07:47
Alright. Does it call for some documentation somewhere so people know why this occurs and is not a defect


abubics
2020-05-04 07:48
We might be able to give a nicer error . . . like, if the file open fails, and we know we're in Windows, and the path is long . . .

tjones
2020-05-04 07:48
You?re right, though - it should be clearer in the pact-js docs, since those are the ones we?re hoping people read

krishnam.misc
2020-05-04 07:48
:slightly_smiling_face:

krishnam.misc
2020-05-04 07:49
I just started with pact an hour ago and I already feel that this is one of the most active and helpful forums in the recent times

tjones
2020-05-04 07:49
It?s actually an interaction between Ruby and Windows, which we hit because Javascript Pact uses the Ruby implementation under the covers

krishnam.misc
2020-05-04 07:49
the other one was Concourse CI

tjones
2020-05-04 07:50
https://bugs.ruby-lang.org/issues/12551 ^ I think this is the bug, but it?s low priority for them

abubics
2020-05-04 07:50
Ah right, so maybe hard for us to catch properly

tjones
2020-05-04 07:50
We?re planning to move to a Rust implementation, which should avoid this class of problems

tjones
2020-05-04 07:51
try pact-js at version `10.0.0-beta.3` if you?re interested to try it

krishnam.misc
2020-05-04 07:52
Sure, thanks for the info. For now, I am evaluating pact and I shall migrate once we finalize

tjones
2020-05-04 07:52
Thank you! That?s really good to hear. It?s really useful hearing feedback too - I?d really like to improve the onboarding for new users. Windows feedback is especially helpful, since none of the core devs even own windows machines

tjones
2020-05-04 07:52
Cool. If you?re evaluating pact for Jest, definitely check out the branch I listed above

tjones
2020-05-04 07:53
actually, I?ll just merge it in.


krishnam.misc
2020-05-04 07:53
I am on this right now.

krishnam.misc
2020-05-04 07:54
Sorry, Did I miss out a detail?

tjones
2020-05-04 07:55
I linked you to a pull request that cleans up the Jest example a bit

tjones
2020-05-04 07:55
but, I figured it was more helpful to merge it. If you do a pull you?ll get a much more streamlined example.

tjones
2020-05-04 07:56
I?m going to spend some time this week updating the examples so they have a common and more realistic client to test

krishnam.misc
2020-05-04 07:57
That was quick :slightly_smiling_face:

tjones
2020-05-04 07:59
I was updating it yesterday :slightly_smiling_face:

tjones
2020-05-04 08:00
I?m probably going to update the `jest-pact` DSL too, to add helpers that make it harder to use wrong. Any feedback would be welcome

tjones
2020-05-04 08:01
Specifically, at the moment, you have to do: ```beforeEach(() => provider.addInteraction({ /* your test setup */}) );```

tjones
2020-05-04 08:01
but it is easy to write that as: ```beforeEach(() => { provider.addInteraction({ /* your test setup */}) });``` (subtle - this version doesn?t return the result of `addInteraction`, which is a promise that you need to wait for)

tjones
2020-05-04 08:02
I?m thinking about adding something like: ```pactInteraction(provider, {/* your test setup */})``` which does the `beforeEach` for you

tjones
2020-05-04 08:03
Anyway, let us know how you go. Even if you end up not going with Pact, hearing about why, and what pain points you had is useful to us.

matt.fellows
2020-05-04 08:29
We have code that detects and warns about it in Pact node, but it can get missed/ignored/squashed

matt.fellows
2020-05-04 08:30
Were not far away from removing Ruby too, which will kill this bug once and for all

krishnam.misc
2020-05-04 11:51
Can someone help me with steps to debug a pact? I must admit that am a newbie here today

matt.fellows
2020-05-05 00:02
What?s the issue you?re having @krishnam.misc? Perhaps start with your problem / needs and we can help. There are some troubleshooting tips in the guide, the rest is standard JS debugging

tjones
2020-05-05 05:24
We get a lot of issues opened where people have forgotten to return the promises to their test framwork. For jest-pact, I?m considering adding a couple of helpers that enforce / assert that promises are returned correctly.

tjones
2020-05-05 05:25
At the moment, a test looks like this: ```beforeEach(() => { return provider.addInteraction({ ...etc, }) }) it("returns a sucessful body", () => { return getMeCats({ url: provider.mockService.baseUrl, }).then(cats => { expect(cats).toEqual(CATS_DATA) }) })```

tjones
2020-05-05 05:27
what do people think of: ```pactInteraction(provider, { ...etc, }) triggerInteraction(() => { return getMeCats({ url: provider.mockService.baseUrl, }).then(cats => { expect(cats).toEqual(CATS_DATA) }) })``` ? (possibly interested: @yousafn, @matt.fellows, @abubics and others)

tjones
2020-05-05 05:28
maybe `testInteraction` rather than `trigger`?

matt.fellows
2020-05-05 05:30
I say this running into a meeting, but _what if_ you overrode the `it` itself, such that the it block had to accept a promise. Then you could just call it `testInteraction` or something and the rest of the code coueld say the same? Or is that what `triggerInteraction` is doing?

abubics
2020-05-05 05:37
I like the concept, but I'm in a very different context atm, so it's hard to switch and say if I'd like to use it :)

tjones
2020-05-05 05:37
Yep, that?s essentially it :slightly_smiling_face:

tjones
2020-05-05 05:39
Or should I say, essentially `it`

tjones
2020-05-05 05:41
```export const pactInteraction = ( provider: pact.Pact, interaction: pact.Interaction | pact.InteractionObject, ) => { beforeEach(() => provider.addInteraction(interaction)); };```

tjones
2020-05-05 05:41
I wish jest had context

tjones
2020-05-05 05:41
then we wouldn?t have to pass in interaction

tjones
2020-05-05 05:42
I also considered having jest-pact override `provider.addInteraction`, but I think that would add confusion for other test frameworks

gunjan.arora
2020-05-05 22:31
has joined #pact-js

krishnam.misc
2020-05-06 12:08
@tjones Could you please help me with below error

krishnam.misc
2020-05-06 12:08
console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99      Actual interactions do not match expected interactions for mock MockService.  Missing requests:        GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea

krishnam.misc
2020-05-06 12:15
My test code is as simple as this: "use strict" const getMeEmail = require("../index").getMeEmail describe("Verify GET Email Contract", () => {   let url = "http://localhost"   const EXPECTED_BODY =      {     "firstName": "Krisham",     "lastName": "Raju",     "email": "",     "lastSent": "2020-05-06T09:43:13.097695",     "inviteId": "e1e06f41-0d48-4a50-899d-e9c5cef56bea",     "status": "EXPIRED",     "roles": [         "UNRESTRICTED_SECONDARY"     ],     "accountNumber": "8069100010141843" }      afterEach(() => {     return provider.verify()   })   describe("works", () => {     beforeEach(() => {       const interaction = {         state: "I have a list of invite emails",         uponReceiving: "a request for a primary user email details",         withRequest: {           method: "GET",           path: "/identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea",           headers: {             Accept: "application/json",           },         },         willRespondWith: {           status: 200,           headers: {             "Content-Type": "application/json",           },           body: EXPECTED_BODY,         },       }       return provider.addInteraction(interaction)     })     // add expectations     it("returns a sucessful body", () => {       return getMeEmail({         url,         port,       }).then(response => {                expect(response.headers["content-type"]).toEqual("application/json")         expect(response.data).toEqual(EXPECTED_BODY)                 expect(response.status).toEqual(200)       })     })   })    })

krishnam.misc
2020-05-06 12:18
The error message is a little ambiguous and I am confused as to what went wrong here. I verified that mockResponse == index.getMeEmail() response

krishnam.misc
2020-05-06 12:19
++ @abubics, @matt.fellows

yousafn
2020-05-06 14:49
Hey, just a friendly note, could you wrap your code in a code block? You can press backtick (`) three times and the code block will appear. You can paste your code in there. It will make it far easier for those reading your code, and make it much easier to help :thumbsup:

yousafn
2020-05-06 15:23
have you got the code for `require("../index").getMeEmail` When you call, you are only passing in a url and port. ``` return getMeEmail({ url, port,``` You?ve setup an interaction, but what is calling `/identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` is that in your getMeEmail function?

tjones
2020-05-06 17:55
@krishnam.misc Have a look in the log files generated by the test. It usually has more about what didn?t match in there.

tjones
2020-05-06 18:00
The error message is telling you that Pact didn?t receive the interaction it expected.

matt.fellows
2020-05-06 23:23
I think Yousaf is right. Your code is not hitting the correct endpoint. Also, and I can?t recall off the top of my head, but you should use the `query` property for the `invite` parameter, it is not technically part of the path (albeit it may still work).

matt.fellows
2020-05-06 23:24
As Tim points out, the log file will probably tell you it got a request that it wasn?t expecting (so that will tell you what your code is actually doing)

krishnam.misc
2020-05-07 04:10
1. Yes, I have the implementation for `require("../index").getMeEmail` `exports.getMeEmail = endpoint => {`   const url = 'https://myapp.url.com'  let token = 'bearer token"   return axios.request({     method: "GET",     baseURL: `${url}`,     url: "/identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea",     headers: { Accept: "application/json",'Authorization': 'Bearer ' + token },   }) 2. The service we are triggering does not need a port.

krishnam.misc
2020-05-07 04:11
@yousafn and @matt.fellows

matt.fellows
2020-05-07 04:11
what do the logs say?

matt.fellows
2020-05-07 04:12
Also, use the `query` property for the query strings, rather than in the path


krishnam.misc
2020-05-07 04:16
getMeEmail response looks like below - which is same as that I put in EXPECTED BODY: {     "firstName": "Krisham",     "lastName": "Raju",     "email": "",     "lastSent": "2020-05-07T04:12:31.531225",     "inviteId": "82cd6f49-b680-4e53-a5ba-4b41890cc531",     "status": "EXPIRED",     "roles": [         "UNRESTRICTED_SECONDARY"     ],     "accountNumber": "8069100010141843" } Here is the detailed log: C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\__tests__> npm run test > pact-example-jest@1.0.0 test C:\ContractTesting\pact-js-master\pact-js-master\examples\jest > jest __tests__/ --runInBand --setupFiles ./pactSetup.js --setupTestFrameworkScriptFile=./pactTestWrapper.js [2020-05-07T04:14:27.812Z] INFO: pact-node@9.0.7/20364 on LTIN114925: Creating Pact Server with options: {"consumer":"MyConsumer-EmailInvite","cors":false,"dir":"C:\\ContractTesting\\pact-js-master\\pact-js-master\\examples\\jest\\pacts","host":"127.0.0.1","log":"C:\\ContractTesting\\pact-js-master\\pact-js-master\\examples\\jest\\logs\\mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider-EmailInvite","spec":2,"ssl":false} [2020-05-07T04:14:29.518Z] INFO: pact-node@9.0.7/20364 on LTIN114925: Created 'standalone\win32-1.70.2\bin\pact-mock-service.bat service --consumer 'MyConsumer-EmailInvite' --pact_dir 'C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\pacts' --host '127.0.0.1' --log 'C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\logs\mockserver-integration.log' --pact-file-write-mode 'update' --port '8991' --provider 'MyProvider-EmailInvite' --pact_specification_version '2'' process with PID: 13872 [2020-05-07T04:14:34.059Z] INFO: pact@9.2.1/20364 on LTIN114925: Setting up Pact with Consumer "MyConsumer-EmailInvite" and Provider "MyProvider-EmailInvite" using mock service on Port: "8991" console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea See C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/logs/mockserver-integration.log for details. [2020-05-07T04:14:36.259Z] ERROR: pact-node@9.0.7/20364 on LTIN114925: Pact Binary Error: Could not load existing consumer contract from C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/pacts/myconsumer-emailinvite-myprovider-emailinvite.json due to 757: unexpected token at 'null'. Creating a new file. [2020-05-07T04:14:36.259Z] ERROR: pact-node@9.0.7/20364 on LTIN114925: Pact Binary Error: [2020-05-07T04:14:36.261Z] INFO: pact@9.2.1/20364 on LTIN114925: Pact File Written [2020-05-07T04:14:36.261Z] INFO: pact-node@9.0.7/20364 on LTIN114925: Removing Pact with PID: 13872 FAIL __tests__/inviteEmaiContractTest.js (9.915s) Verify GET Email Contract works × returns a sucessful body (2182ms) ? Verify GET Email Contract ? works ? returns a sucessful body Request failed with status code 404 at createError (node_modules/axios/lib/core/createError.js:16:15) ? Verify GET Email Contract ? works ? returns a sucessful body Pact verification failed - expected interactions did not match actual. at new VerificationError (node_modules/@pact-foundation/pact/errors/verificationError.js:19:42) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total

krishnam.misc
2020-05-07 04:26
mock server response looks like below: `I, [2020-05-07T09:51:17.374485 #19584]  INFO -- : Registered expected interaction GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` `D, [2020-05-07T09:51:17.374485 #19584] DEBUG -- : {`   `"description": "a request for a primary user email details",`   `"providerState": "I have a list of invite emails",`   `"request": {`     `"method": "GET",`     `"path": "/identity/invite",`     `"query": {`       `"inviteId": [`         `"e1e06f41-0d48-4a50-899d-e9c5cef56bea"`       `]`     `},`     `"headers": {`       `"Accept": "application/json"`     `}`   `},`   `"response": {`     `"status": 200,`     `"headers": {`       `"Content-Type": "application/json"`     `},`     `"body": {`       `"firstName": "Krisham",`       `"lastName": "Raju",`       `"email": "",`       `"lastSent": "2020-05-06T09:43:13.097695",`       `"inviteId": "e1e06f41-0d48-4a50-899d-e9c5cef56bea",`       `"status": "EXPIRED",`       `"roles": [`         `"UNRESTRICTED_SECONDARY"`       `],`       `"accountNumber": "8069100010141843"`     `}`   `}` `}` `W, [2020-05-07T09:51:19.780783 #19584]  WARN -- : Verifying - actual interactions do not match expected interactions.`  `Missing requests:`   `GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` `W, [2020-05-07T09:51:19.780783 #19584]  WARN -- : Missing requests:`   `GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` I, [2020-05-07T09:51:19.802723 #19584]  INFO -- : Cleared interactions W, [2020-05-07T09:51:19.832643 #19584]  WARN -- : Could not load existing consumer contract from C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/pacts/myconsumer-emailinvite-myprovider-emailinvite.json due to 757: unexpected token at 'null'. Creating a new file. E, [2020-05-07T09:51:19.832643 #19584] *ERROR* -- : 757: unexpected token at 'null' (JSON::ParserError) C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/node_modules/@pact-foundation/pact-node/standalone/win32-

krishnam.misc
2020-05-07 04:27
While the sample looks simple and easy, not sure why the basic example does not get through

matt.fellows
2020-05-07 04:29
Just a reminder - please format your code with the triple backticks. Or use this feature

matt.fellows
2020-05-07 04:31
It looks like there is an existing pact contract file that has invalid json - care to share it?

matt.fellows
2020-05-07 04:32
also, I suspect your query param is still wrong. is `inviteId` expected to be an array i.e. `inviteId[]=1234` or singular `inviteId=1234` type thing? I suspect the latter

krishnam.misc
2020-05-07 04:32
you are right, its singular

matt.fellows
2020-05-07 04:32
can you please upload the full contents of the log file as an attachment?

krishnam.misc
2020-05-07 04:34
Log

matt.fellows
2020-05-07 04:37
So that log file is conclusive - you?re not sending a request to the mock service

matt.fellows
2020-05-07 04:37
you can see it registered an expectation, and when the test completed, it never received a request and so failed

matt.fellows
2020-05-07 04:38
The request needs to be configured to point at the pact mock service

matt.fellows
2020-05-07 04:38
so the `url` that is given to `getMeEmail` must be the url of the pact mock service

matt.fellows
2020-05-07 04:40
You can either a) specify the exact port pact should be running on when you create a new `Pact(?)` or b) let it dynamically choose a port and grab the values from the pact object e.g. https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js#L87-L92

matt.fellows
2020-05-07 04:41
@tjones :point_up: this problem happens a lot. I?m wondering if in JS land we should do something like what nock does, and hijack the HTTP runtime and automatically route the request to the mock service?)

matt.fellows
2020-05-07 04:41
just a thought

tjones
2020-05-07 05:14
Could be good! If we can find a nice way to do this cross platform, then yeah

tjones
2020-05-07 05:15
That was also part of the motivation for `jest-pact` - I wanted to get the url + port directly from the provider, without needing to ensure it was different in each test

tjones
2020-05-07 05:16
I think if we wrote wrappers along those lines for all the other popular test frameworks, it would be clear what parts should be directly written into the pact-js DSL

tjones
2020-05-07 05:17
For example, jest-pact has this (but I can?t remember why): https://github.com/pact-foundation/jest-pact/blob/master/src/index.ts#L33

matt.fellows
2020-05-07 07:46
> I think if we wrote wrappers along those lines for all the other popular test frameworks, it would be clear what parts should be directly written into the pact-js DSL I agree, that would be really instructive for the next generation of API design

a.smith
2020-05-07 08:18
has joined #pact-js

krishnam.misc
2020-05-07 10:49
@matt.fellows so the `url` that is given to `getMeEmail` must be the url of the pact mock service I am confused. If we are just hitting the mock server, then, where exactly would the validation happen between the actual endpoint call and mock response before a pact/contract is generated under Pacts dir

matt.fellows
2020-05-07 10:59
The pact contract is generated from the consumer side without ever talking to the real provider

matt.fellows
2020-05-07 11:00
the contract generated is then shared to a provider

matt.fellows
2020-05-07 11:00
the provider build runs separately

krishnam.misc
2020-05-07 11:00
This is my overall understanding of how pact works in steps below: 1. We will define what is the expected response from a real service call in `const EXPECTED_BODY` 2. We will build the actual interaction in `describe("works", () =>`  3. `it("returns a sucessful body", ()` - Here we are validating that the actual service endpoint response is same as what we mocked. This is how we are adding expectations. 4. All expectations/contracts created are shared with Provider who will validate against his own endpoint changes to confirm contract is not broken

matt.fellows
2020-05-07 11:00
Think of Pact on the consumer side, as a unit test of your client code.

matt.fellows
2020-05-07 11:01
> 3. it(?returns a sucessful body?, () - Here we are validating that the actual service endpoint response is same as what we mocked. This is how we are adding expectations. No, you don?t hit the _actual_ endpoint, you only talk to Pact

tjones
2020-05-07 11:02
The verification against the actual real endpoint is done later

tjones
2020-05-07 11:03
this is one of the value props of Pact: you don?t need to spin up the client and the server at the same time


tjones
2020-05-07 11:04
see here for some diagrams

krishnam.misc
2020-05-07 11:12
[2020-05-07T11:11:36.245Z] INFO: pact@9.2.1/27860 on LTIN114925: Setting up Pact with Consumer "MyConsumer-EmailInvite" and Provider "MyProvider-EmailInvite" using mock service on Port: "8991" [2020-05-07T11:11:36.589Z] INFO: pact@9.2.1/27860 on LTIN114925: Pact File Written [2020-05-07T11:11:36.591Z] INFO: pact-node@9.0.7/27860 on LTIN114925: Removing Pact with PID: 28708 PASS __tests__/inviteEmaiContractTest.js (18.671s) Verify GET Email Contract works ? returns a sucessful body (249ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 22.954s Ran all test suites matching /__tests__\\/i. [2020-05-07T11:11:38.754Z] INFO: pact-node@9.0.7/27860 on LTIN114925:

tjones
2020-05-07 11:12
Please format your code with three backticks ```

krishnam.misc
2020-05-07 11:12
```[2020-05-07T11:11:36.245Z] INFO: pact@9.2.1/27860 on LTIN114925: Setting up Pact with Consumer "MyConsumer-EmailInvite" and Provider "MyProvider-EmailInvite" using mock service on Port: "8991" [2020-05-07T11:11:36.589Z] INFO: pact@9.2.1/27860 on LTIN114925: Pact File Written [2020-05-07T11:11:36.591Z] INFO: pact-node@9.0.7/27860 on LTIN114925: Removing Pact with PID: 28708 PASS __tests__/inviteEmaiContractTest.js (18.671s) Verify GET Email Contract works ? returns a sucessful body (249ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 22.954s Ran all test suites matching /__tests__\\/i. [2020-05-07T11:11:38.754Z] INFO: pact-node@9.0.7/27860 on LTIN114925:```

krishnam.misc
2020-05-07 11:13
Apologies for lengthy comments - @tjones

yousafn
2020-05-07 11:13
Took me a little while to get my head round it, but then I was like ta-daaaaaa!

krishnam.misc
2020-05-07 11:16
I might need some time to get this concept into my lazy head :smile:

matt.fellows
2020-05-07 11:17
it does take some time

matt.fellows
2020-05-07 11:17
We?re in the process of creating an explainer video, that hopefully can do that job in < 3 minutes. Wish us luck

krishnam.misc
2020-05-07 11:17
Is there a sample provider code that I can refer and see how this contract I generated is validted?


tjones
2020-05-07 11:19
there?s a provider test in here


tjones
2020-05-08 02:06
No, that?s an example provider

krishnam.misc
2020-05-11 11:46
So,do we need to publish the pact we generated even before it can be accessed by Provider? I suppose, this would happen when we are hosting our pacts on some server

tjones
2020-05-11 11:47
It?s best to use a broker, yeah

tjones
2020-05-11 11:47
but you don?t have to - any way you can share pacts is fine

krishnam.misc
2020-05-11 11:47
and can you give me a direct link to a sample provider test. I could not find any.

krishnam.misc
2020-05-11 11:48
sharing pacts is fine in general context, but in a CI mode, its good that they are available online?


tjones
2020-05-11 11:48
Yes, your life is definitely easier with the pact broker

krishnam.misc
2020-05-11 11:50
unfortunately, this example relies on a broker to be running

krishnam.misc
2020-05-11 11:51
If I need to get this working in static mode?


tjones
2020-05-12 04:43
@krishnam.misc did you get it working?

krishnam.misc
2020-05-12 04:43
nope :disappointed:

krishnam.misc
2020-05-12 04:44
This seems to be a little tricky

tjones
2020-05-12 04:47
What was your problem? Maybe I can help

tjones
2020-05-12 04:49
If you modify the example to use `pactUrls: [ './path-to-your-pact.json']`, and remove the broker specific variables (pactBrokerUsername, pactBrokerPassword, pactBrokerUrl, publishVerificationResult, etc), it should work

krishnam.misc
2020-05-12 04:50
pact-js-master\examples\e2e\test\provider.spec.js I was looking into this example and try to write a Provider test but that gives me errors while publishing the provider. Implement Provider  Implement Consumer Install pact package from npm Install test runner like Jest Write Consumer test to generate pact json file Execute Consumer test which will generate pact json publish pact file to pact broker Write provider test with pact broker Execute provider test We are done from steps 1 to 6

tjones
2020-05-12 04:51
What error do you get?

tjones
2020-05-12 04:52
Above, you said you were looking for an example that didn?t use the pact broker

tjones
2020-05-12 04:52
so if your pact is not in the broker, you won?t be able to publish the verification result

tjones
2020-05-12 04:52
note that the flow goes: Consumer test -> writes pact publish pact -> broker

tjones
2020-05-12 04:52
then,

tjones
2020-05-12 04:53
broker -> gives pact to provider test provider test -> publishes verification success (or failure) to broker

tjones
2020-05-12 04:53
if you are manually providing the pact to the provider test, you won?t be able to publish a verification status

krishnam.misc
2020-05-12 04:56
.

tjones
2020-05-12 04:56
can you edit that to be in ``` please?

krishnam.misc
2020-05-12 04:56
```PS C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\__tests__> curl -v -XPUT -H "Content-Type: application/json" -d ..\pacts\myconsumer-emailinvite-myprovider-emailinvite.json http://localhost/pacts/provider/MyProvider-EmailInvite/consumer/MyConsumer-EmailInvite/version/1.0 Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" value of type "System.String" to type "System.Collections.IDictionary". At line:1 char:18 + curl -v -XPUT -H "Content-Type: application/json" -d ..\pacts\myconsu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand```


tjones
2020-05-12 04:59
So, that?s a curl command that doesn?t work in powershell - see here:


tjones
2020-05-12 04:59
anyway, publishing the pact manually with curl isn?t necessary

tjones
2020-05-12 04:59
you can use pact-js to do it



tjones
2020-05-12 05:01
Alternatively, you can use the binstub that `pact-node` provides

tjones
2020-05-12 05:02
```...in your package json: "pactPublish": "pact publish --pact-files-or-dirs pacts --consumer-version \"$(git describe)\" --pact-broker \"$PACT_BROKER_HOST\" --pact-broker-username \"$PACT_BROKER_USERNAME\" --pact-broker-password \"$PACT_BROKER_PASSWORD\"",```

krishnam.misc
2020-05-12 05:18
ok, let me take a look

krishnam.misc
2020-05-12 07:00
C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\publish.js:8 .trim() ^ ReferenceError: childProcess is not defined at exec (C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\publish.js:8:6) at Object.<anonymous> (C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\publish.js:12:45)

krishnam.misc
2020-05-12 07:01
publish.js seems to have muliple conditions to meet

krishnam.misc
2020-05-12 07:01
if (http://process.env.CI !== "true") {   console.log("skipping Pact publish as not on CI...")   process.exit(0) }

krishnam.misc
2020-05-12 07:02
I removed this part, as I am running this in local. But we also have other conditions around TRAVIS, etc

tjones
2020-05-12 07:02
how are you invoking it? `childProcess` is part of node

krishnam.misc
2020-05-12 07:03
Not to rant, the sample example is usually simple to adapt and generate more interest to embrace the product. However, i have a diff feeling here.

tjones
2020-05-12 07:03
I agree. I?m working on improving the examples at the moment.

krishnam.misc
2020-05-12 07:03
may be I am alone finding it diff to get this working, not sure.

krishnam.misc
2020-05-12 07:05
I am just running "test" from package.json file

tjones
2020-05-12 07:05
Some of the issues you have run in to have been unrelated to pact (eg running the curl command in powershell). But, it does illustrate that our documentation could be improved - the curl command you had came from someone?s blog, rather than the pact documentation.

krishnam.misc
2020-05-12 07:05
Agree. But I am just trying to find diff ways to get past this simple PoC

tjones
2020-05-12 07:05
By the way, I think the best way is to call the pact-publish command from the package json, as in the second snippet I sent you above

tjones
2020-05-12 07:06
The ability to do this is in the documentation, but I?d like to surface it more

krishnam.misc
2020-05-12 07:13
``` "pactPublish": "pact publish --pact-files-or-dirs pacts --consumer-version concumser-1.0 --pact-broker localhost:9009"```

krishnam.misc
2020-05-12 07:17
``` Executing task: npm run pactPublish < pact-example-jest@1.0.0 pactPublish C:\ContractTesting\pact-js-master\pact-js-master\examples\jest pact publish --pact-files-or-dirs pacts --consumer-version concumser-1.0 --pact-broker localhost:9009 Could not find command "publish".```

tjones
2020-05-14 02:12
Ah yes, sorry. I gave you completely the wrong example.

tjones
2020-05-14 02:13
Try: ``` pact-broker publish pacts --consumer-app-version=concumser-1.0 --broker-base-url=http://localhost:9009```

tjones
2020-05-14 02:14
by the way, I would recommend not hardcoding your version

hans.brouwer
2020-05-14 07:18
has joined #pact-js

cesar.lopes
2020-05-15 12:31
```"overview": "All versions of `http-proxy` are vulnerable to Denial of Service. An HTTP request with a long body triggers an `ERR_HTTP_HEADERS_SENT` unhandled exception that crashes the proxy server. This is only possible when the proxy server sets headers in the proxy request using the `proxyReq.setHeader` function. \n\nFor a proxy server running on `http://localhost:3000`, the following curl request triggers the unhandled exception: \n```curl -XPOST http://localhost:3000 -d \"$(python -c 'print(\"x\"*1025)')\"```", "recommendation": "No fix is currently available. Consider using an alternative package until a fix is made available.",```

cesar.lopes
2020-05-15 12:32
do we have any ticket to replace http-proxy?

tjones
2020-05-15 12:33
We don?t, and could accept a fix if someone wanted to make one. However, I don?t think this is a practical problem. The proxy is only spun up locally during tests, and the worst that could happen is someone could interrupt your CI process if they had access to your CI environment (and if that has happened, you have bigger problems than someone interrupting your pact tests).

cesar.lopes
2020-05-15 12:37
Ok, my pipeline is currently broken because it fail on npx audit

matt.fellows
2020-05-15 13:29
With respect Cesar, that's not our problem. If the package can be upgraded then great. We'll accept a PR or if you'd like to raise an issue please do. I suspect if it's a new vulnerability, snyk will notify us.

matt.fellows
2020-05-15 13:30
A blanket security rule is useless if you don't know what the problems are. That vulnerability simply is not an issue for the use case.

matt.fellows
2020-05-15 13:34
You could ignore dev dependencies or find other ways to manage vulnerabilities.

closenet.uk
2020-05-15 13:40
same here, 4 vulnerabilities @pact-foundation/pact package

closenet.uk
2020-05-15 13:40
@matt.fellows can you help with that?

cesar.lopes
2020-05-15 13:45
I understand @matt.fellows ty for the answers

cesar.lopes
2020-05-15 13:45
:+1:

matt.fellows
2020-05-15 14:10
I'm trying to say we don't care, obviously we do!

yousafn
2020-05-15 14:38
you can either use audit-ci to skip particular vulns, https://github.com/IBM/audit-ci

yousafn
2020-05-15 14:38
@closenet.uk Hey Mo!

cesar.lopes
2020-05-15 14:38
that?s what I did, ty @yousafn

closenet.uk
2020-05-15 14:57
hey @yousafn :slightly_smiling_face:

closenet.uk
2020-05-15 14:58
disabled devDependecies in audit, cheers guys

raghu.alapati1
2020-05-16 00:07
has joined #pact-js

antonello
2020-05-18 06:33
Morning! The eachLike matcher expects a minimum array length of 1. How to match an array that can be empty? The java dsl has, for example, minArrayLike.

tjones
2020-05-18 06:33
Use an empty array

tjones
2020-05-18 06:34
An empty array is a separate test case (otherwise you could have passing tests that never test the contents of the array)

antonello
2020-05-18 06:35
That?s fair! Thank you! I should?ve thought of that :)

tjones
2020-05-18 06:36
No worries :slightly_smiling_face: It?s a common question, we should add it to the docs for `eachLike`


matt.fellows
2020-05-18 08:00
My first PR to the Ruby part of the code base, or at least an early one

antonello
2020-05-18 08:12
awesome, I think it?s the right thing.

antonello
2020-05-18 08:15
An approach that one of the teams has gone for (at least on a specific instance that I?m aware of) is to define an interaction with a minimal response, where minimal means with only the properties and values that are not optional and empty arrays for properties where that?s allowed. This can be sensible in the case of relatively big responses where having a state or interaction for, for example, each array that can be empty would lead to quite a large number of interactions.

tjones
2020-05-18 08:16
I think ideally, you would create interactions with the minimal response that you need, and all the properties that you understand / use

matt.fellows
2020-05-18 08:16
kind of like a min and max set?

antonello
2020-05-18 08:21
Yep, I think that?s what I mean. :slightly_smiling_face:

matt.fellows
2020-05-18 08:21
That seems a reasonable starting point for most I think

matt.fellows
2020-05-18 08:22
And then if strange/weird edge cases start to emerge, you can get more specific

antonello
2020-05-18 08:22
There are some (old) endpoints that rightly or wrongly would require a huge amount of interactions to cover all possible and meaningful examples.

antonello
2020-05-18 08:30
So yes, min set and max set are good starting points. Probably max set is not enough in the majority of cases, even as a starting point.

tjones
2020-05-18 08:49
Yeah- testing all permutations of possible responses is hard to cover even in traditional unit tests. I think it?s good to make a reasonable choice about what to cover, and it sounds like you?re making good choices in your situation

yousafn
2020-05-18 14:49
how did you guys managed to disable devDependecies in audit-ci? I?d like that option but couldn?t find it in the docs

matt.fellows
2020-05-18 22:28
```npm audit --only=prod```

robert.strauch_slack
2020-05-18 23:46
has joined #pact-js

robert.strauch_slack
2020-05-18 23:57
Good evening, We're having a web application based on VueJS. In order to isolate its testing I'd like to introduce pact-js for the communication to the provider. As written in the https://github.com/pact-foundation/pact-js#example > Write your tests - the important thing here is that you test the outbound _collaborating_ function which calls the Provider, and not just issue raw http requests to the Provider. In a Vue application there's a Vue component which has a method, e.g. `submit()`. This method issues an HTTP request. Would the above mean that the consumer test should preferrably invoke the `submit()` method instead of something like `axios.get()`?

tjones
2020-05-19 00:10
Almost. Usually, the pattern would be the other way around

tjones
2020-05-19 00:11
So, your vue component and your consumer test both call an API layer

tjones
2020-05-19 00:11
separating the API concern from the component


tjones
2020-05-19 00:12
here?s a React example, but the principle is the same

tjones
2020-05-19 00:14
For vue: ```new Vue({ el: '#app', data () { return { info: null } }, mounted () { axios .get('https://api.coindesk.com/v1/bpi/currentprice.json') .then(response => (http://this.info = response)) } })```

tjones
2020-05-19 00:14
This is the example in the docs

tjones
2020-05-19 00:26
For Pact, you?d want to do something like: ``` mounted () { api.getPrices() .then(response => (http://this.info = response)) }``` Irrespective of pact, I like this better, because it separates how to get the data from what to do with it

matt.fellows
2020-05-19 02:12
yep. Separate out front end / display logic from integration logic

matt.fellows
2020-05-19 02:13
makes things much more testable

robert.strauch_slack
2020-05-19 07:03
Yeah, that's what I was thinking of. The problem is that our current codebase is somewhat messy and that API calls are made sirectly with axios from within the component. Maybe we need some refactoring first :stuck_out_tongue:

tjones
2020-05-19 07:04
I think that is likely to be true whatever test framework you choose

robert.strauch_slack
2020-05-19 07:07
Thanks for your help, guys... this clears some things for me :slightly_smiling_face:

jarmy
2020-05-22 16:58
has joined #pact-js

robert.strauch_slack
2020-05-24 20:37
Dear pact-js members, I'm still taking my first steps with Pact and there's one thing I couldn't get running. There is a REST resource on the provider side for registering new users. On a successful registration, this resource responds with HTTP 200 and a Bearer token in the response header like `Authorization: Bearer someToken`. This is the interaction on the consumer side but the mock response does not contain `Authorization: Bearer someToken` ```await provider.addInteraction({ state: "default", uponReceiving: "register new user", withRequest: { method: "POST", path: "/register" }, willRespondWith: { status: 200, headers: { "Authorization": "Bearer TOKEN" } } });```

matt.fellows
2020-05-24 23:20
It definitely should return that header, can you show some logs or something proving otherwise?

matt.fellows
2020-05-24 23:20
The mock server will show what it thinks it needs to return

matt.fellows
2020-05-24 23:20
If you could share the test code, the logs or both that would be helpful. Most helpful would be to fork an example in the JS repository and show the bug in action

paul.davies
2020-05-27 04:05
has joined #pact-js

tjones
2020-05-28 01:27
In addition to Matt?s comment, this code returns `Bearer TOKEN`, but your question is about `Bearer someToken`.

sairsule
2020-05-30 10:49
has joined #pact-js

danhitchcock
2020-06-01 15:55
has joined #pact-js

weyert.deboer
2020-06-01 21:56
has joined #pact-js

lankala321
2020-06-05 03:24
has joined #pact-js

lankala321
2020-06-05 03:33
I am getting this error. ERROR in node_modules/@pact-foundation/pact-node/src/message.d.ts(6,32): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/pact.d.ts(23,55): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(24,47): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(25,49): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-web/dsl/options.d.ts(35,45): error TS2304: Cannot find name 'Exclude'. src/api/services/auth.service.pact.spec.ts(16,7): error TS2345: Argument of type '{ consumer: string; provider: string; port: number; }' is not assignable to parameter of type 'PactWebOptions'. Object literal may only specify known properties, and 'consumer' does not exist in type 'PactWebOptions'.

lankala321
2020-06-05 03:37
I am following this article.



lankala321
2020-06-05 03:40
I am setting up pact karma using npm install --save-dev @pact-foundation/karma-pact @pact-foundation/pact-node @pact-foundation/pact-web

lankala321
2020-06-05 03:41
can somebody please help me what should i do to fix this issue.

tjones
2020-06-05 03:46
It looks like you?re not passing the right options to PactWeb - can you provide your code?

tjones
2020-06-05 03:51
The example code you linked to works for me. How are you configuring your Pact settings?

lankala321
2020-06-05 03:54
import { HttpClientModule } from '@angular/common/http'; import { service } from './abc.service'; import { User } from './../models/user'; import {TestBed} from '@angular/core/testing'; import { Matchers, PactWeb } from '@pact-foundation/pact-web' describe('UserServicePact', () => { let provider; // Setup Pact mock server for this service beforeAll(async () => { /*provider = await new Pact({*/ provider = await new PactWeb({ consumer: 'webclient', provider: 'service', port: 1234 }); // required for slower CI environments await new Promise(resolve => setTimeout(resolve, 1000)); // Required if run with `singleRun: false` await provider.removeInteractions(); }); // Configure Angular Testbed for this service beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpClientModule ], providers: [ service ] }); }); // Verify mock service afterEach(async () => { await provider.verify(); }); // Create contract afterAll(async () => { await provider.finalize(); }); describe('get()', () => { const userId = 1; const expectedMeDetails: User = { id: '123', username: 'xyz', enabled: true, accountNonExpired: true, accountNonLocked: true, }; beforeAll(async () => { await provider.addInteraction({ state: `get me details`, uponReceiving: 'a request to GET me details', withRequest: { method: 'GET', path: `/me` }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedMeDetails) } }); }); it('should get a user', async () => { const service: service = TestBed.get(service); await http://service.me().toPromise().then(response => { expect(response).toEqual(expectedMeDetails); }); }); });

abubics
2020-06-05 03:57
(as a little aside, using the "code block" formatting in Slack will make your code samples much easier to read & distinguish against conversation messages)

tjones
2020-06-05 03:57
What version of typescript are you using?

lankala321
2020-06-05 03:58
```2.4.2```

tjones
2020-06-05 03:59
Could you try again with typescript 3? It looks like the definitions we are exporting aren?t compatible with typescript 2. Apologies for not having this documented

lankala321
2020-06-05 03:59
sure

tjones
2020-06-05 04:03
Looks like this was introduced in pact-node 9.01 - I didn?t expect it would be a breaking change.

lankala321
2020-06-05 04:04
ERROR in node_modules/@pact-foundation/pact-node/src/message.d.ts(6,32): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/pact.d.ts(23,55): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(24,47): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(25,49): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-web/dsl/options.d.ts(35,45): error TS2304: Cannot find name 'Exclude'. src/api/services/auth.service.pact.spec.ts(16,7): error TS2345: Argument of type '{ consumer: string; provider: string; port: number; }' is not assignable to parameter of type 'PactWebOptions'. Object literal may only specify known properties, and 'consumer' does not exist in type 'PactWebOptions'.

lankala321
2020-06-05 04:04
same errors

tjones
2020-06-05 04:05
I believe `Cannot find name 'unknown'` is caused by using TS 3 types with TS 2

tjones
2020-06-05 04:06
Can you tell us which versions you are using of pact-web / pact-node, and typescript please?

tjones
2020-06-05 04:06
Also, does the example code you linked work for you?

lankala321
2020-06-05 04:06
```"@pact-foundation/karma-pact": "^2.3.1", "@pact-foundation/pact-node": "^10.9.5", "@pact-foundation/pact-web": "^9.11.0",```

tjones
2020-06-05 04:07
would you be able to share an example repository that I can use to reproduce the problem?

lankala321
2020-06-05 04:09
yes. I am working on it i will provide.

tjones
2020-06-05 04:09
Thanks!

lankala321
2020-06-05 04:21
05 06 2020 00:12:26.007:INFO [Chrome 83.0.4103 (Windows 10.0.0)]: Connected on socket E1XhRprV1Vk04NpdAAAA with id 24754627 WARN: 'Passing in consumer/provider to PactWeb is deprecated, and will be removed in the next major version' Chrome 83.0.4103 (Windows 10.0.0): Executed 0 of 7 SUCCESS (0 secs / 0 secs) WARN: 'Passing in consumer/provider to PactWeb is deprecated, INFO: 'Setting up Pact using mock service on port: "1234"' Chrome 83.0.4103 (Windows 10.0.0): Executed 0 of 7 SUCCESS (0 secs / 0 secs) INFO: 'Setting up Pact using mock service on port: "1234"' 05 06 2020 00:12:33.461:WARN [proxy]: failed to proxy /api/users/42 (connect ECONNREFUSED 127.0.0.1:1234) 05 06 2020 00:12:35.464:WARN [proxy]: failed to proxy /api/users/42 (connect ECONNREFUSED 127.0.0.1:1234) 05 06 2020 00:12:37.469:WARN [proxy]: failed to proxy /api/users/42 (connect ECONNREFUSED 127.0.0.1:1234) Chrome 83.0.4103 (Windows 10.0.0) UserServicePact update() should update a user FAILED HttpErrorResponse: Http failure response for /api/users/42: 0 Unknown Error Error: PopsicleError: Unable to connect to "http://127.0.0.1:1234/interactions/verification" at new VerificationError (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22530:1) at http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:20163:1 at tryCatch (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:488:1) at invokeCallback (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:503:1) at publish (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:477:1) at publishRejection (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:418:1) at MutationObserver.flush (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:207:1) at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:359:1) at Zone.runGuarded (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:134:1) at MutationObserver.<anonymous> (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:118:1) Chrome 83.0.4103 (Windows 10.0.0): Executed 1 of 7 (1 FAILED) (0 secs / 10.422 secs) Chrome 83.0.4103 (Windows 10.0.0) UserServicePact update() should update a user FAILED HttpErrorResponse: Http failure response for /api/users/42: 0 Unknown Error Error: PopsicleError: Unable to connect to "http://127.0.0.1:1234/interactions/verification" at new VerificationError (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22530:1) at http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:20163:1 at tryCatch (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:488:1) at invokeCallback (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:503:1) at publish (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:477:1) at publishRejection (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:418:1) at MutationObserver.flush (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:207:1) at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:359:1) at Zone.runGuarded (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:134:1) Chrome 83.0.4103 (Windows 10.0.0) ERROR { "message": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node _modules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at XMLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:3 91:1)\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-everg reen.js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/ dist/zone-evergreen.js:1629:1)", "str": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node_mod ules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at X MLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:391:1 )\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen .js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist /zone-evergreen.js:1629:1)" } Chrome 83.0.4103 (Windows 10.0.0): Executed 1 of 7 (1 FAILED) ERROR (0 secs / 10.422 secs) Chrome 83.0.4103 (Windows 10.0.0) ERROR { "message": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node _modules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at XMLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:3 91:1)\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-everg reen.js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/ dist/zone-evergreen.js:1629:1)", "str": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node_mod ules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at X MLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:391:1 )\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen .js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist /zone-evergreen.js:1629:1)" Chrome 83.0.4103 (Windows 10.0.0): Executed 1 of 7 (1 FAILED) ERROR (13.691 secs / 10.422 secs) [2020-06-05T04:12:41.975Z] INFO: pact-node@10.2.2/24448 on lan: Removing all Pact servers. [2020-06-05T04:12:41.976Z] INFO: pact-node@10.2.2/24448 on lan: Removing Pact with PID: 10236 ERROR: The process "10236" not found.

lankala321
2020-06-05 04:21
example files also throwing errors

tjones
2020-06-05 04:31
There should be lines like this in the log above the quote you sent: ```10% building 1/1 modules 0 active[2020-06-05T04:29:51.809Z] INFO: pact-node@10.2.2/7337 on Timothys-MBP.fritz.box: Creating Pact Server with options: {"cors":true,"spec":3,"port":1234,"log":"/Users/tim/office/pact/pact-example-angular-spring-boot/consumers/angular8-karma/logs/mockserver-integration.log","dir":"/Users/tim/office/pact/pact-example-angular-spring-boot/pacts","pactFileWriteMode":"overwrite","ssl":false,"host":"localhost"} 05 06 2020 14:29:53.499:INFO [pact]: Pact Mock Server running on port: 1234 05 06 2020 14:29:53.543:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/```

lankala321
2020-06-05 04:38
yes i have those lines

lankala321
2020-06-05 04:40
10% building 1/1 modules 0 active[2020-06-05T04:11:55.168Z] INFO: pact-node@10.2.2/24448 on : Creating Pact Server with options: {"cors":true,"spec":3,"port":1234,"log":"C:\\Users\\IdeaProjects\\pact-example-angular-spring-boot\\consumers\\angular8-karma\\logs\\mocks erver-integration.log","dir":"C:\\Users\\IdeaProjects\\pact-example-angular-spring-boot\\pacts","pactFileWriteMode":"overwrite","ssl":false,"h ost":"localhost"} [2020-06-05T04:11:57.035Z] ERROR: pact-node@10.2.2/24448 on Ulankala: Pact Binary Error: C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/ standalone/win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/app.rb:5:in `require': cannot load such file -- pact/co nsumer/mock_service/cors_origin_header_middleware (LoadError) from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/app.rb:5:in `<top (required)>' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/run.rb:2:in `require' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/run.rb:2:in `<top (required)>' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/cli.rb:33:in `require' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone 05 06 2020 00:12:25.179:ERROR [pact]: Error while trying to run karma-pact: Error: Couldn't start Pact with PID: 10236

tjones
2020-06-05 04:53
That looks like the windows 10 pathing issues, see: https://github.com/pact-foundation/pact-node/issues/100

phil.endsley
2020-06-05 14:14
has joined #pact-js

lankala321
2020-06-05 17:41
example file is working for me. That was windows path issue

lankala321
2020-06-07 03:06
Hi team, actual interactions do not match expected interactions for mock mock service. I am getting this error pacts files not getting generated.

lankala321
2020-06-07 03:07
Can anybody know how to overcome these

matt.fellows
2020-06-07 03:07
it means what your test code is doing does not match what you said it would do

matt.fellows
2020-06-07 03:07
please share your consumer test and any log files

lankala321
2020-06-07 03:14
describe('UserServicePact', () => { let provider; // Setup Pact mock server for this service beforeAll(async () => { provider = await new PactWeb({ }); // required for slower CI environments await new Promise(resolve => setTimeout(resolve, 1000)); // Required if run with `singleRun: false` await provider.removeInteractions(); }); // Configure Angular Testbed for this service beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpClientModule ], providers: [ Service ] }); }); // Verify mock service afterEach(async () => { await provider.verify(); }); // Create contract afterAll(async () => { await provider.finalize(); }); describe('get()', () => { const expected: User = { id: '123', username: 'test', firstName: 'xyz', lastName: 'abc', }; beforeAll(async () => { await provider.addInteraction({ state: `Get User`, uponReceiving: 'a request to Get User Details', withRequest: { method: 'GET', path: `http://localhost:1234/User`, headers: {'Content-Type': 'application/json'}, query: "" }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedDetails) } }); }); it('should get a user', async () => { const service: UserService = TestBed.get(UserService); await service.getUser().toPromise().then(response => { expect(response).toEqual(expected); }); }); });

lankala321
2020-06-07 03:20
Log file:

lankala321
2020-06-07 03:20
I, [2020-06-06T22:06:01.771382 #4336] INFO -- : Registered expected interaction GET /User D, [2020-06-06T22:06:01.771382 #4336] DEBUG -- : { "description": "a request to Get User Details", "providerState": "Get User", "request": { "method": "GET", "path": "/User", "headers": { "Content-Type": "application/json" } }, "response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::SomethingLike", "contents": { "id": "123", "username": "test", "firstName": "xyz", "lastName": "abc", } } }, "metadata": null } W, [2020-06-06T22:06:01.780417 #4336] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /User I, [2020-06-06T22:06:03.151564 #4336] INFO -- : Cleared interactions

matt.fellows
2020-06-07 03:21
path should just be `/User`. Is `UserService` configured to hit the pact mock service instead of the real thing?

lankala321
2020-06-07 03:28
I tried /User also it was not working i am getting same errors. So I used localhost beforeAll(async () => { await provider.addInteraction({ state: `Get User`, uponReceiving: 'a request to Get User Details', withRequest: { method: 'GET', path: `/User`, headers: {'Content-Type': 'application/json'}, query: "" }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedDetails) } });

matt.fellows
2020-06-07 03:28
The log file above is very clear - it did not see a request to `/User`. Please ensure your UserService is configured to point to the Pact Mock service on whatever port you?ve configured Pact to run on

lankala321
2020-06-07 03:39
My userservice class is like this

lankala321
2020-06-07 03:39
@Injectable() export class UserService { baseUrl = environment.userServiceBaseUrl;

lankala321
2020-06-07 03:40
what changes should i make here

matt.fellows
2020-06-07 03:40
what port are you starting pact on

lankala321
2020-06-07 03:40
userServiceBaseUrl is pointing to the actual url

lankala321
2020-06-07 03:40
1234

matt.fellows
2020-06-07 03:40
it should point to `http://localhost:1234`

lankala321
2020-06-07 03:41
pact: [ { cors: true, spec: 3, port: 1234, consumer: 'ui', provider: 'userservice', log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pact') } ], proxies: { '/api': 'http://localhost:1234' }

lankala321
2020-06-07 03:41
this is my my karma.conf

matt.fellows
2020-06-07 03:42
thx, sorry I don?t know karma very well

matt.fellows
2020-06-07 03:42
I think any api calls that go to `/api/*` will be proxied, but you?re not using that

matt.fellows
2020-06-07 03:42
I could be wrong, you?ll need to read the docs

lankala321
2020-06-07 03:55
thank you. I tried even this one http://localhost:1234 not working.

lankala321
2020-06-07 03:56
Do you have any refernces for github working codes for angular.

matt.fellows
2020-06-07 04:04
what does the log file say after you updated the endpoint?



lankala321
2020-06-07 04:17
It is giving same error even after updating.

matt.fellows
2020-06-07 04:17
what do the logs say

matt.fellows
2020-06-07 04:18
the logs will tell you how you?re interacting with Pact

matt.fellows
2020-06-07 04:18
if no request is coming in, that?s all todo with your angular/karma setup

matt.fellows
2020-06-07 04:18
I?m afraid I can?t tell you how to configure your own setup

lankala321
2020-06-07 04:30
I, [2020-06-07T00:28:54.008388 #18500] INFO -- : Cleared interactions I, [2020-06-07T00:28:55.351390 #18500] INFO -- : Cleared interactions

lankala321
2020-06-07 04:30
I am just getting this now and pact is not generating

matt.fellows
2020-06-07 05:57
that can?t be the whole log file

matt.fellows
2020-06-07 05:57
It should first ?register an interaction? (as per above)

matt.fellows
2020-06-07 05:58
If you can provide a reproducable example we could help troublesheet (e.g. a working git repository)

tjones
2020-06-07 10:34
@lankala321 I think you?ve got the `proxies` setting from the example repository you linked, but it?s not appropriate for your API. Try `proxies: { '/User': 'http://localhost:1234' }`

lankala321
2020-06-07 21:23
@tjones, Thank you. I fixed the proxy issues. It is working fine now.

lankala321
2020-06-08 07:48
How to publish pacts to pact broker from angular project?

matt.fellows
2020-06-08 12:30
It has nothing to do with Angular


cristian.schez
2020-06-09 11:21
has joined #pact-js

godfrey
2020-06-10 07:35
has joined #pact-js

pact.io971
2020-06-11 01:13
has joined #pact-js

matt.fellows
2020-06-11 02:23
we are looking for more JS core maintainers. As now the _second most_ popular Pact library (in terms of stars) we have a lot we?d like to do. Our top priority is building a healthy community and sustainable contributor base. https://github.com/pact-foundation/pact-js/issues/451ssues tagged `good first issue` or `help wanted` could be a great place to start https://github.com/pact-foundation/pact-js/labels/help%20wanted

bradley.smith
2020-06-11 23:03
has joined #pact-js

michaelphi
2020-06-16 22:36
has joined #pact-js

yousafn
2020-06-17 23:00
has anyone come across this before, looks pretty cool? https://github.com/ASaiAnudeep/pactum


tjones
2020-06-17 23:10
Oh, that?s cool! I?ve been wanting to add better configuration to pact-js for a while

tjones
2020-06-17 23:11
Unless I?m missing something, in terms of features, this only adds some new environment variables?

tjones
2020-06-17 23:12
> Publish Pacts to broker > Check if if?s safe to deploy > Start stub loclly using the Pact contract ^ This is part of pact-node already. It highlights that we should improve the documentation substantially

yousafn
2020-06-17 23:13
I started looking into it and yes it looks like just some additional scripts which point to the cli executables, and the env vars which are set, are automatically picked up by the cli tool

yousafn
2020-06-17 23:14
I use those features out of the box with pact-js, but I suppose it worked for their use case (minimal effort, same lines in a package.json can be replicated easily across of their projectts) I just have a shared verifier and publishing script that is used by any of our microservices which use pact

tjones
2020-06-17 23:14
I might reach out to them - better lifecycle and configuration a the direction I?d like to take pact-js

yousafn
2020-06-17 23:15
Aye, always nice to get real world feedback, especially for the future roadmap of jest-pact, pact-js and the like. You never really know what people really care about, and what they want, without chatting to them :slightly_smiling_face: You are deffo more of a people person than me :right-facing_fist:

yousafn
2020-06-17 23:16
I?ve been off work for 2 weeks, looking forward to getting back in and showing the guys all the stuff I?ve been doing with serverless and pact

matt.fellows
2020-06-17 23:17
Wow, that?s interesting

matt.fellows
2020-06-17 23:18
So, it looks like Pact?but I can?t see any dependency on it

matt.fellows
2020-06-17 23:19
But the DSL does have some niceities about it - similar to the nock discussion I was having with Tim recently

matt.fellows
2020-06-17 23:20
They?ve done a very decent job of documenting and there seems to be a lot of care/thinking involved - we should def chat

matt.fellows
2020-06-17 23:21
Might just be me, but I genuinely feel like the last few weeks the community members here have lifted their game - it?s so awesome to see

yousafn
2020-06-17 23:30
There also looked to be the beginning of a pact js native implementation using request interceptors https://github.com/seek-oss/nodejs-consumer-pact-interceptor

yousafn
2020-06-17 23:31
Sounds exactly like the nock discussion. i used it to build a slack mock web server for my integration tests in a slack package I?ve published and it?s been fantastic

matt.fellows
2020-06-17 23:37
So, I worked with the team who wrote that :stuck_out_tongue:

matt.fellows
2020-06-17 23:37
(it was actually my first client at DiUS, and my first exposure to Pact)

yousafn
2020-06-17 23:41
Right, so pactum basically uses polka which is an express style alternative to spin up a mock server, and you are correct, no pact deps, looks like it will create a pact file at the end, which on very cursory glance looks like it meets pact v2

yousafn
2020-06-17 23:44
the docs are brilliant. Hat deffo tipped. I like the split readme?s for diff things rather than shoehorning into one big readme as it cana be. terribly daunting or people will ctrl + f and that is it

tjones
2020-06-17 23:52
Yeah! It?s so inspiring

a.smith
2020-06-18 16:25
Is anyone using jest-pact on Windows? My tests appear to be failing intermittently, and I can't quite see why. This is logged to the console: ```[2020-06-18T16:13:22.004Z] ERROR: pact-node@10.9.5/43640 on IESO-LAP155: Pact Binary Error: Could not load existing consumer contract from C:/path/to/pacts/pact/consumer-provider.json due to 757: unexpected token at 'null'. Creating a new file.```

a.smith
2020-06-18 16:30
I've a Ruby stack trace I can share privately. Might be a pact-standalone problem rather than jest-pact.

a.smith
2020-06-18 17:05
(PS: I found the bug reports about file locking, etc. on Windows. I don't know if this is the same issue.)

tjones
2020-06-18 23:25
Are you running your tests with `--runInBand` ?

tjones
2020-06-18 23:26
I?ve hit this on a mac, but I can?t remember the solution. I think it was a configuration issue, but if it?s happening regularly I?d love to improve the error message

a.smith
2020-06-19 08:43
@tjones thanks for the reply :slightly_smiling_face: We don't think we are using `--runInBand`, but I'm just going to check the create-react-app docs to make sure...

tjones
2020-06-19 08:49
So, when we created jest-pact, I thought it would mean tests could be run in parallel. However, I think sometimes it means that the pact writing collides (which might be what you?re experiencing)

tjones
2020-06-19 08:51
If you?re using CRA, you can use: ```"test": "react-scripts test --runInBand"```

tjones
2020-06-19 08:51
I will add this to the docs tomorrow, apologies for missing it.

tjones
2020-06-19 08:51
(and, please let me know if this doesn?t fix your problem)

a.smith
2020-06-19 09:23
No worries! ~This doesn't seem to have fixed the issue though, sadly~ :disappointed: It has fixed the issue, thank you :slightly_smiling_face:

a.smith
2020-06-19 09:54
I think I've also found that the log file for earlier tests in a run is overwritten by later tests in the same run.

a.smith
2020-06-19 14:31
I haven't been able to find any resources yet about using Pact with batched/paged result sets. Let's say I want to retrieve all the orders a particular customer has placed. That might be 0, 1, many, or "lots". 0 and 1 results obviously fit on one page; let's assume "many" is also sufficiently small to fit on a single page, but "lots" is more than that: e.g. 104 orders placed by that customer with 25 orders per page. How would you go about writing interactions for that kind of API?

uglyog
2020-06-20 03:01
I would test first page, last page and middle page with unit tests, and then have Pact tests to test a page which has a next page, and one that does not.

tjones
2020-06-21 09:33
@a.smith Good pickup! Would you be able to open an issue against jest-pact so it doesn?t get forgotten?

a.smith
2020-06-22 07:36
Nice one, thanks @uglyog

a.smith
2020-06-25 09:09
@tjones Now done :+1: Sorry it's a bit sketchy.

tjones
2020-06-25 09:46
Thanks - it?s clear and has repro instructions, which is all we need. I?ll try to get a fix out in the next couple days.

ayyamuthutechnical
2020-06-25 17:56
has joined #pact-js

ag.robinson
2020-06-27 15:40
has joined #pact-js

chandanakurumeti27
2020-06-29 11:34
has joined #pact-js

tjones
2020-06-29 11:36
The code sample you have above looks right to me. What problems are you having?

tjones
2020-06-29 11:39
Oh, I see what you mean. You could do: ```before("setup provider general hook", done => { Promise.all([provider.setup(), provider_savedames.setup()]).then(() => { done() }) })```

matt.fellows
2020-06-29 12:04
You?re already using async/await elsewhere, I?d just go for this

matt.fellows
2020-06-29 12:04
```before(async () => { await provider1.setup() await provider2.setup() })```

chandanakurumeti27
2020-06-29 12:20
It didnt help either, same logs again

chandanakurumeti27
2020-06-29 12:21
Thanks @tjones and @matt.fellows for your suggestions

matt.fellows
2020-06-29 12:58
You need to configure your code - the one making the http calls - to point at the different providers

matt.fellows
2020-06-29 12:58
from the outside, it looks like you?re testing at too high a level (i.e. multiple interactions in a single test)

matt.fellows
2020-06-29 12:58
If you can split it into separate tests, things will be much better - easier to maintain, easier to understand, less configuration like this, and it will have more of the good properties of a unit test

chandanakurumeti27
2020-06-29 14:18
yeah i tried to do that as well, but my consumer code base is too complex to split that specific function getsavedgames. so decided to have it like this. and am sure that its just not more than two contracts.

chandanakurumeti27
2020-06-29 14:21
@matt.fellows Can you please provide me some example link for the same, like how to configure my code in such a way that it talks to two different providers. I remember that it is possible in pact jvm by mentioning two provider names inside @pactverification annotation @pactverification(?provider1?,?provider2")

chandanakurumeti27
2020-06-29 14:21
but couldnt find any example for the same in javascript

matt.fellows
2020-06-29 22:06
Presumably your code has a way of configuring where it sends it's http requests. You need to set one to localhost:10000 and the other to localhost:10001 (or whatever you set the ports to)

matt.fellows
2020-06-29 22:07
Make your http client code configurable (maybe thru the use of an env var) and the sent them to the correct URL before you run the pact test

matt.fellows
2020-06-29 22:08
All JS example have this for one provider, it's the same process for more than 1

matt.fellows
2020-06-30 00:03
If you don?t specify the port in the Pact configuration, it will just assign a random available port - you can get the port and configure your http client after calling `setup()` e.g. https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js#L87-L92

abubics
2020-06-30 02:01
Maybe a helpful note here is: this isn't fundamentally a Pact concept. This is a "how you architect your code" concept, and you need to provide interfaces in your own code that allow this kind of configuration. For example, you might have an API client that takes a `baseUrl` constructor parameter. Or `host` and `port` params. This is all up to you as a dev, whether you use Pact or not.

amaljayaraj07
2020-06-30 08:51
has joined #pact-js

chandanakurumeti27
2020-06-30 10:53
Hi , is this possible in pact js as well?


chandanakurumeti27
2020-06-30 10:53
If so , can someone please provide the example link ?

matt.fellows
2020-06-30 10:54
No sorry it's not. You could possibly use request filters/state handlers to attempt the same

chandanakurumeti27
2020-06-30 10:54
Thank you Matt :slightly_smiling_face:

chandanakurumeti27
2020-06-30 10:55
Is it good practice to use requestfilters to change the request body itself?

chandanakurumeti27
2020-06-30 10:56
Anyways thank you for your prompt response :blush:

chandanakurumeti27
2020-06-30 10:57
FYI, my consumer is javascript based one and provider is java based service here

tjones
2020-06-30 10:58
Usually no. Why do you need to do this?

chandanakurumeti27
2020-06-30 10:58
Now, how can i use the pact jvm framework request filters to replace something in the request without using this feature of `"valuefrom providerstate"` ?

chandanakurumeti27
2020-06-30 10:58
very confused now

chandanakurumeti27
2020-06-30 10:59
As i mentioned in the channel, consumer is javascript service where i used pact js framework to write consumer tests and published the contract. Now while running the provider tests i want to replace the request body value with which i get from provider states

chandanakurumeti27
2020-06-30 11:00
and my provider here is java based service wher aam using pact jvm framework to have provider junit tests

tjones
2020-06-30 11:04
Ah, sorry- I didn?t realise this was a follow-on question. My bad.

chandanakurumeti27
2020-06-30 11:05
No prob at all, can you please help me on this , like how can i proceed in this sceanrio as above

tjones
2020-06-30 11:05
I?m not across the state parameters from v3, but the request filters would be done on the provider tests

tjones
2020-06-30 11:05
Usually I implement this with a state handler on the server, setting up the state that is expected

tjones
2020-06-30 11:06
in v2 pacts, there?s conceptually a mapping from the state string to the state you setup, so my state would be something like `"A user exists with user ID 10"`

tjones
2020-06-30 11:07
then you can use a provider state handler to set up the provider

tjones
2020-06-30 11:07
it?s not as elegant as the provider state callback feature

chandanakurumeti27
2020-06-30 11:08
Just to be clear for you, my req in the contract is to `authentication/session/get` which has body like {?sessionuid? : ?7eyudow223"} so before runnning the provider(java service) tests, using `statechange` method, i planned to create a session and i will get `sessionuid` as a response when i create a session in statechange method

chandanakurumeti27
2020-06-30 11:09
And I want to use the `sessiouid` i have in contract with the one which i get form `statechange method` before running provider tests

chandanakurumeti27
2020-06-30 11:10
This is my exact problem right now, as `consumer` and `provider` are using two diff languages `(JS and Java)`, it looks complicated to me

tjones
2020-06-30 11:13
I think it may be straightfoward, but you might not be able to use the provider state value injection feature (so you will just have to use regular provider state strings). I?m in the middle of something at the moment, but I?ll drop back in an hour or so and outline a solution (if someone else hasn?t already)

chandanakurumeti27
2020-06-30 11:14
sure thank you :+1:

chandanakurumeti27
2020-06-30 13:49
@phil.endsley yeah, but not exaclty what i want yet.,can you please help me on this?

phil.endsley
2020-06-30 14:17
I would think it depends on what you're doing. For your case above, setting a sessionUid in the request body, I think it's fine. I would also defer to the docs and core maintainers for best practices. In our case, we modify the request by adding auth headers. We don't include the auth headers as part of our pacts, though. https://docs.pact.io/implementation_guides/jvm/provider/junit/#modifying-the-requests-before-they-are-sent

greg.tyler
2020-07-02 09:46
has joined #pact-js

ravi.mijar
2020-07-03 06:53
has joined #pact-js

sarathojha
2020-07-03 12:33
has joined #pact-js

ravi.mijar
2020-07-07 05:52
Hello.. I'm writing some provider verification tests for a node-express API. I've followed the pact workshop and some other blogs to get to a point where I can run the `npm run test:pact` using jest. It reads the local contract from a directory and tries to run the interactions with the API running in the other terminal. I'm running this on a Windows laptop. However, I constantly see this - ```Unsupported Media Type: unsupported media type application/x-www-form-urlencoded at BodySchemaParser.toSchema```

matt.fellows
2020-07-07 06:07
Hi Ravi!

matt.fellows
2020-07-07 06:07
Glad to see you giving it a go

matt.fellows
2020-07-07 06:07
we may need more information to find out where things are going wrong here.

matt.fellows
2020-07-07 06:08
Did you mean to be sending using `application/json` or is it indeed a form post?

ravi.mijar
2020-07-07 06:21
it isn't a form post.. I fiddled around with some of the values in the contract file, but I get the same error..

abubics
2020-07-07 06:41
It might be a better/easier idea to change the test that outputs the pact file, rather than manually editing the contract :thinking_face:

matt.fellows
2020-07-07 07:15
Can you please share the code or something? As it stands, it?s too hard to understand. It doesn?t look like a Pact specific code, so it could be in your library or something upstream

matt.fellows
2020-07-07 07:15
My guess is that you have body parser that is expected another media type, but is getting `application/x-www-form-urlencoded`.

matt.fellows
2020-07-07 07:16
If you?re editing the contract and it?s not working, there is likely an issue on the provider code

ravi.mijar
2020-07-07 19:51
Last night, I found a possible cause. I haven?t proven it yet. After @abubics suggested to look at the consumer tests, I found that the `http://axios.post` I have is not configured for any headers. That may be a reason why the contract doesn?t have it in the right format or something. Will try to do this later today and post here.

matt.fellows
2020-07-07 22:04
You still need to add the header explicitly in the test to ensure your code behaves the way it should too. Share the test code and we can help

yousafn
2020-07-08 18:22
Hey to any users of the serverless framework. I?ve built a plugin for serverless that will allow you to start a pact stub service by providing a pact file in your serverless.yml file. Currently only supports macosx but will update shortly to download the corresponding binaries for the underlying OS https://github.com/YOU54F/serverless-offline-pact

yousafn
2020-07-08 18:24
Additionally, I?ve also built a lambda template that can be used to host a pact stub service as a lambda function backed by api gateway. https://github.com/YOU54F/serverless-pact This was an iteration over using ecs with docker images containing the pact stub service and a contract file

matt.fellows
2020-07-08 23:31
This is awesome, in fact, I think we?ll try and use it on one of the internal Pactflow systems :stuck_out_tongue:

yousafn
2020-07-09 00:39
I was looking at some of the packages and mechanisms that pact-js/pact-node uses to download the binaries for the various os?s, in the case of serverless-offline-pact. It?s easy with serverless-pact as the lambda runtime is a known quantity. Would be ace to see it used in pact-flow, I?ve still to implement it at work, been caught up in lots of things in the two weeks being back. Will be able to do some cost comparisons against running it in ecs vs lambda over a certain time period. Not that I am too fussed, as I am not paying the bills :slightly_smiling_face:

matt.fellows
2020-07-09 00:57
haha

matt.fellows
2020-07-09 00:58
Sorry, I was referring to the offline pact (we have a few control-plane microservices that could use it)

matt.fellows
2020-07-09 00:58
the serverless-pact deployment would require a lot more testing to ensure all of the features worked reliably etc.

matt.fellows
2020-07-09 00:58
We do actually use ECS for our platform.

matt.fellows
2020-07-09 00:58
100% lambda would be cheaper, I could probably do some back of the envelope numbers, but it would be significant

matt.fellows
2020-07-09 00:59
I think it would probably halve our bill. Our main costs are EC2, RDS and all of the automations on the back of cloudtrail events.

matt.fellows
2020-07-09 01:00
Lambda (which is used for all of the control plane services) is costing us, like, $10's of dollars /mth or something

ayyamuthutechnical
2020-07-09 09:11
@matt.fellows, Currently i am working on doing consumer contract test for frontend using js. While trying to publish in local pact-broker i am getting below issue. Can you please help on this ```[2020-07-09T09:02:25.790Z] INFO: pact-node@10.9.5/14812 on HUNANMBP18: Publishing Pacts to Broker [2020-07-09T09:02:25.791Z] INFO: pact-node@10.9.5/14812 on HUNANMBP18: Publishing pacts to broker at: https://localhost:8090 [2020-07-09T09:02:36.260Z] WARN: pact-node@10.9.5/14812 on HUNANMBP18: Pact exited with code 1. [2020-07-09T09:02:36.260Z] ERROR: pact-node@10.9.5/14812 on HUNANMBP18: Could not publish pact: Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 1 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 2 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 3 of 3 Failed to tag version 15.0 of FrontendWebsite due to error: Errno::ECONNREFUSED - Connection refused - connect(2) for "localhost" port 8090} One or more pacts failed to be published Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" Pact contract publishing failed: Error: Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 1 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 2 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 3 of 3 Failed to tag version 15.0 of FrontendWebsite due to error: Errno::ECONNREFUSED - Connection refused - connect(2) for "localhost" port 8090} One or more pacts failed to be published Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" at ChildProcess.<anonymous> (/Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/src/publisher.js:72:40) at Object.onceWrapper (events.js:417:26) at ChildProcess.emit (events.js:322:22) at maybeClose (internal/child_process.js:1021:16) at Socket.<anonymous> (internal/child_process.js:443:11) at Socket.emit (events.js:310:20) at Pipe.<anonymous> (net.js:672:12)```

matt.fellows
2020-07-09 12:25
I mean, that looks pretty clear to me - the pact publish step is unable to communicate to the broker

matt.fellows
2020-07-09 12:26
if you?re running the publish step in docker, but the pact broker is not in the same environment they will not be able to communicate

matt.fellows
2020-07-09 12:26
are you sure the broker is running on port `8090`?

ayyamuthutechnical
2020-07-09 14:03
@matt.fellows, thanks i have mapped the wrong port number. I have changed and now it is working fine. Thanks for the help. Have a great day

jarmy
2020-07-09 20:45
Hi. I?d like some clarification on pact verification regarding `providerVersionTag` vs `providerVersionsTag`. When I use `providerVersionTag: [gitBranch, TEST_ENV]`, I get this warning message ```[2020-07-09T20:17:34.917Z] WARN: pact-node@10.9.4/92598 on jarmy-m02: 'consumerVersionTag' and 'providerVersionTag' have been deprecated, please use 'consumerVersionTags' or 'providerVersionTags' instead``` Followed by this ``` INFO: Tagging version 8e6353a of graphql as "http://DEVTOOLS-561-ja-integrate-pact.io" INFO: Tagging version 8e6353a of graphql as "shared"``` The provider version is updated with those tags in the pact matrix. If I use `providerVersionsTag: [gitBranch, TEST_ENV],` nothing is logged and no tags are applied. Is there a more preferred way to tag the provider version?

matt.fellows
2020-07-09 23:27
You keep referring to `providerVersionsTag` but the error message says to migrate to `providerVersionTags`. Basically, we did something stupid and gave it a dumb name - it should have been a pluralised version of what you were using that?s currently working

abubics
2020-07-10 01:48
the `s` is on `Tags` not `Versions` :slightly_smiling_face: maybe the problem is it's hard to read the diff on that long warning line?

matt.fellows
2020-07-10 02:11
personally, I would just copy what is in the error message - but happy for suggestions!

matt.fellows
2020-07-10 02:11
(also, the TypeScript bindings should give hints if you?re using a _good_ editor :stuck_out_tongue: )

tjones
2020-07-10 04:00
Only if you?re using TypeScript :stuck_out_tongue:

matt.fellows
2020-07-10 04:26
well, VS code should bring the types in for pure JS projects e.g. here is an example JS provider (https://github.com/pactflow/example-provider) and code completion works :ok_hand:

matt.fellows
2020-07-10 04:28
I?m not sure about other editors. But I imagine Sublime and Atom at the very least also have pretty decent support. Heck, it works in my vim

matt.fellows
2020-07-10 04:30
We actually publish the types as part of the release, specifically for non-TypeScript users to get this exact benefit

matt.fellows
2020-07-10 04:31
Not to drag it out, but you can see the types are also sent along with the package to give info to IDEs

tjones
2020-07-10 07:25
Huh, that?s cool

jason
2020-07-14 10:15
has joined #pact-js

chris.mitchell
2020-07-14 12:12
has joined #pact-js

danhitchcock
2020-07-15 14:47
Hi, I've just come back to my pact tests to update them and it appears the JS end(Client) seems to be failing on each test with ``` Cannot open port 1234 on ipv4 or ipv6 interfaces at ../node_modules/@pact-foundation/src/common/net.ts:27:13``` Currently scratching my head, as i didn't change anything in the tests since they last ran successfully.

yousafn
2020-07-15 17:55
whats running on 1234 your client or the mock server? have you got anything running on 1234 anyway? you done a netstat? Assuming this is failing locally on your machine only, if you revert your changes , is it still ok

yousafn
2020-07-15 17:57
1234 is quite a low port number so i?d always choose much higher or random ports and pass it into your client

matt.fellows
2020-07-15 22:43
I would avoid explicit port allocation, if you don't set the port pact will find a free one for you and return it in the call to setup()

matt.fellows
2020-07-16 01:25
It may be a previous pact test that was terminated without being able to clean up processes

matt.fellows
2020-07-16 01:26
if you?re on a mac/linux, you could do this

matt.fellows
2020-07-16 01:26
`lsof -i :1234` to see what process is holding the port

danhitchcock
2020-07-16 09:37
Aha almost forgot, i solved this, and it seemed to have been caused by out of date versions, I might update the port allocation now just to be safe.

chandanakurumeti27
2020-07-16 12:31
Hello there! I am trying run provider tests for my JS based provider service and To make those tests isolated , i wanted to use `nock` which basically intercepts the calls from the provider and sends back required response to my provider while running the pact provider tests. But I can see that the `nock` couldnt intercept the request calls from my provider. Is it because pact has no integration with nock or something am missing? Please respond and am looking forward to any reply or help. This is my provider tests looks like.

chandanakurumeti27
2020-07-16 12:33
And i made sure that my provider service which is listening at localhost:5059 talks to localhost:8088 before running these tests

chandanakurumeti27
2020-07-16 12:34
But getting `"connect refused"` error!

matt.fellows
2020-07-16 12:37
I don't see how your provider is being started in that process, so I'm not sure what effect nock would have

matt.fellows
2020-07-16 12:38
Nock can't intercept request happening in a separate process

chandanakurumeti27
2020-07-16 12:51
I started my provider manually sepeartely, so does that need to be included in test code it self?

matt.fellows
2020-07-16 12:59
Its up to tou. I normally would (see also our examples). If you want to use nock that way though it needs to happen in the same process the provider is running otherwise it will have no effect.

chandanakurumeti27
2020-07-16 13:06
Yeah you are right, when i included the step of starting the provider and pointing that to nock inside the provider tests, then it is working fine

chandanakurumeti27
2020-07-16 13:06
Thank you so much for your help!

chandanakurumeti27
2020-07-16 13:06
Have a great day :slightly_smiling_face:

matt.fellows
2020-07-16 13:10
You too!

os.shulyak
2020-07-17 07:09
has joined #pact-js

tjones
2020-07-18 05:10
For fans of `jest-pact`, I?ve just released 0.7.0, which includes two new DSL functions: `xpactWith` (which skips the tests inside it) and `fpactWith` (which only runs the tests inside it) - these match Jest?s `xdescribe` and `fdescribe`.

yousafn
2020-07-18 08:52
Ace! I?ve heard on .only and .skip but not the x/f prefixed equiv. good work!

tjones
2020-07-18 08:52
Probably, we should actually support both.

tjones
2020-07-18 10:44
Thoughts on `pactWith.only` and `pactWith.skip` ? Also, I realised recently that `pactWith` is potentially confusing, because it?s only for consumer tests. I?m not sure that there?s any extra handling necessary for Jest in a provider test (in fact, a test framework isn?t even necessary for provider verification). Any thoughts on whether it?s worth clarifying this at the DSL?

yousafn
2020-07-18 20:55
It may be, does it cause confusion? the verifier exposed through pact-node is the pact version. Maybe we need to make it clear this is for the consumer side only?

paul.stitt
2020-07-23 09:24
has joined #pact-js

fernando.martin
2020-07-23 12:58
has joined #pact-js

gcoradini
2020-07-23 13:01
has joined #pact-js

poojashree_gopal
2020-07-27 04:00
has joined #pact-js

david025
2020-07-28 16:39
has joined #pact-js

daniel.pritchard
2020-07-28 16:51
has joined #pact-js

guilherme.correa-ext
2020-07-28 19:45
has joined #pact-js

paul.fairless
2020-07-28 21:48
has joined #pact-js

matias.waterloo
2020-07-30 12:22
has joined #pact-js

maciej.olko
2020-07-31 08:01
has joined #pact-js

maciej.olko
2020-07-31 08:01
Hello, is there a way to make pact-js generate v2 specs?

matt.fellows
2020-07-31 08:11
umm? it does generate v2 specs.

matt.fellows
2020-07-31 08:11
or are you referring to the beta branch?

matt.fellows
2020-07-31 08:12
If you are using the message features, that will always generate a v3 pact

maciej.olko
2020-07-31 08:14
thanks for the response, I thought it generates v3 because we see warnings while verifying with pact-python; I have to double check that

matt.fellows
2020-07-31 08:14
hmm let me know

matt.fellows
2020-07-31 08:14
If you are using the standard install `@pact-foundation/pact/@latest` it will generate v2 by default

matt.fellows
2020-07-31 08:15
in fact, it basically cant? generate anything else, unless you are using the ?message? feature

srinivasan.sekar1990
2020-07-31 10:36
has joined #pact-js

maciej.olko
2020-07-31 11:57
for what it?s worth I published a question on #pact-python about the problem: https://pact-foundation.slack.com/archives/C9VECUP6E/p1596195216224800

francis.lobo
2020-08-04 22:48
has joined #pact-js

brendan.j.donegan
2020-08-07 10:39
Hi folks. We're trying to do provider verification using pact-js and we keep getting an error back from the broker, 405. Is our broker too old?

matt.fellows
2020-08-07 10:43
which versions of things are you using? `405` would potentially indicate that a resource doesn?t exist that new code needs which versions of things do you have?

brendan.j.donegan
2020-08-07 11:04
How do I find the pact broker version?

brendan.j.donegan
2020-08-07 11:04
Is it shown anywhere in the UI?

matt.fellows
2020-08-07 11:09
click on the ?API Browser? and you?ll see it in the headers

matt.fellows
2020-08-07 11:09
(or via any direct API call)

brendan.j.donegan
2020-08-07 11:16
Yeah, it's 2.39.0 and we are trying to use the latest version of pact js

matt.fellows
2020-08-07 11:19
ok yeah, so getting on close to 1 year old. There?s a bunch of new things in the broker that we?ll be taking advantage of

matt.fellows
2020-08-07 11:19
were you using any new features in Pact JS or did you just do an upgrade?

brendan.j.donegan
2020-08-07 11:42
This is the first time we are needing to use it for verification

brendan.j.donegan
2020-08-07 11:43
Until now we've only used the consumer side, and the providers have been pact-jvm

matt.fellows
2020-08-07 11:45
Gotcha. It?s likely calling the new pacts for verification feature (which is almost certainly something you want). Any reason why you can?t upgrade the broker?

brendan.j.donegan
2020-08-07 11:48
No reason, just wanted to make sure it would work before going through it :D

brendan.j.donegan
2020-08-07 11:49
Another question while you're here. We have a problem with HTTPS, do you happen to know where certificates need to be put for ruby to find them?

brendan.j.donegan
2020-08-07 11:52
I may as well kill two birds with one stone and get that working while upgrading

matt.fellows
2020-08-07 11:53
when you say you have issues with https, can you elaborate - is it the client calling the server which has a self-signed cert, or is it the broker issuing outbound calls (via e.g. webhooks) to targets with self-signed certs?

matt.fellows
2020-08-07 11:53
`$SSL_CERT_FILE` or `$SSL_CERT_DIR` for the clients (see https://github.com/pact-foundation/pact-ruby-standalone/releases amongst other places)


brendan.j.donegan
2020-08-07 11:54
Basically if we try to communicate with the broker using HTTPS it fails

brendan.j.donegan
2020-08-07 11:54
Webhooks seem to be ok

matt.fellows
2020-08-07 11:54
ok cool, then the above environment variables should do


brendan.j.donegan
2020-08-07 11:55
They are to be set to the path containing the pem file when launching the broker?

brendan.j.donegan
2020-08-07 11:55
Sorry, I should say, the client does have the self signed certificate

brendan.j.donegan
2020-08-07 11:55
But the broker doesn't

matt.fellows
2020-08-07 11:56
the broker doesn?t need the certificate, whatever load balancer / web server in front of it will have the certificate

matt.fellows
2020-08-07 11:56
(e.g. nginx)

brendan.j.donegan
2020-08-07 11:57
I should probably loop back with our infra team and if I have more specific questions I'll come back here

matt.fellows
2020-08-07 11:57
your clients (e.g. Pact JS, which is Ruby under the hood) will need to know that the broker is presenting a self-signed certificate, and have it configured to trust it

matt.fellows
2020-08-07 11:58
if you?re going to bother the infra team, tell them to go out and setup a real (free) certificate using letsencrypt and this problem goes away (they will likely not appreciate said comment)

brendan.j.donegan
2020-08-07 11:58
:joy:

brendan.j.donegan
2020-08-07 11:59
I think I get what you're saying now though, will try that first

brendan.j.donegan
2020-08-07 12:00
So set SSL_CERT_FILE when running, for example the pact-broker command

brendan.j.donegan
2020-08-07 12:07
I understand what was happening now. We run the CI in a standard node docker container which doesn't have the client cert. We'd need to add it in there :+1:

brendan.j.donegan
2020-08-07 12:07
Cheers for the help

matt.fellows
2020-08-07 12:12
you?re welcome

matt.fellows
2020-08-07 12:13
Just note (and I know it?s confusing) that setting the certificate for NodeJS using standard Node config files won?t help - Pact JS actually bundles a Ruby app (which is the main engine) which is the thing that actually talks to the broker. So those env vars are likely still needed)

jacques.murekezi
2020-08-11 16:29
has joined #pact-js

jacques.murekezi
2020-08-11 16:29
Hi All, I have this function: ```saveApplication(details: Application): Observable<any> { return http://this.http.post(`http://localhost:5000/Apply`, details); }``` And I am writing a Pact Test for it (API contract testing) and below is the test: ```describe('ApplicationService contract testing', () => { let provider: PactWeb; let applicationService: ApplicationService; beforeAll(function (done) { provider = new PactWeb({ cors: true, host: '127.0.0.1', port: 9776, logLevel: 'error' }); setTimeout(done, 2000); provider.removeInteractions(); }); afterAll(function (done) { provider.finalize().then(function () { done(); }, function (err) { done.fail(err); }); }); beforeEach(() => { TestBed.configureTestingModule({ providers: [ApplicationService], imports: [HttpClientTestingModule] }); applicationService = getTestBed().get(ApplicationService); }); afterEach((done) => { provider.verify().then(done, e => done.fail(e)); }); describe('Save', () => { const _details: Application = { title: 'Mr', firstName: 'Application', lastName: 'applicant', dob: new Date(1977, 10, 10).toString(), gender: 'M' }; beforeAll((done) => { provider.addInteraction({ state: ' a task to save the dashboard application to mongo', uponReceiving: ' a request to post', withRequest: { method: 'POST', headers: { 'Content-Type': 'application/json' }, path: '/Apply', body: _details }, willRespondWith: { status: 201, headers: { 'Content-Type': 'application/json' } } }).then(done, e => done.fail(e)); it('should call the API to Post the application Content', (done) => { const _response: any = {}; applicationService.saveApplication(_details).subscribe(res => { expect(res).toEqual(_response); done(); }, error => { done.fail(error); } ); }); }); }); });``` The test isn't running when id npm run test or ng test, ut the pacts directory is being created. I don't know what is missing from my configs This is what I have in Karma: ``` frameworks: ['jasmine', '@angular-devkit/build-angular','pact'], plugins: [...., require('@pact-foundation/karma-pact')], pact: [{ cors: true, port: 9776, consumer: "ui", provider: "Apply", dir: "pacts/", spec: 2 }], proxies: { '/api/applications/v1/': 'http://localhost:9776/Apply/' },``` Not sure what I am missing. any help?

joel.whalen
2020-08-11 19:44
How do I match a field that can be either null or an array? Is multiple type checking supported by pact-js?

uglyog
2020-08-11 23:12
The recommendation is to use two tests, one for each value you want in the contract

matt.fellows
2020-08-12 01:25
What do you mean by ?the test isn?t running?? as in, the `it` block isn?t firing? That would imply an issue unrelated to Pact, or at least, if Pact is throwing an error you?re missing it somehow

matt.fellows
2020-08-12 01:25
If it?s creating the Pact directory, that implies the mock server part (the karma) bit _is_ running

matt.fellows
2020-08-12 01:26
I don?t know angular/karma very well, but worth looking to see if Pact is generating any logs (defaults to `./log`)

yousafn
2020-08-12 02:03
are you expecting saveApplication to be hitting the pack mock? ```saveApplication(details: Application): Observable<any> { return http://this.http.post(`http://localhost:5000/Apply`, details); }``` ``` provider = new PactWeb({ cors: true, host: '127.0.0.1', port: 9776, logLevel: 'error' });``` your mock provider is starting up but your app code should be using port `9776` in you test in order for the request to hit the mock

matt.fellows
2020-08-12 02:11
:point_up:

jacques.murekezi
2020-08-12 07:01
@yousafn what do you mean by that?

jacques.murekezi
2020-08-12 07:09
@matt.fellows I have checked there is no ./log folder

matt.fellows
2020-08-12 10:09
Set the log dir in your karma config

matt.fellows
2020-08-12 10:10
That should allow you to specify where the logs are written

matt.fellows
2020-08-12 10:11
I think the angular proxy configuration above redirects to the mock server, am I write? Otherwise what Yousaf is trying to say is that you need to make sure your client code is configured to use the mock service you started, not whatever the default is

matt.fellows
2020-08-12 10:12
Maybe increase loglevel also

jacques.murekezi
2020-08-12 14:46
well the proxy should either use the mocked server. I switched to live server and nothing happened

jacques.murekezi
2020-08-12 14:46
how do you add log level though? not sure if angular allows logs on the webapp level

joel.whalen
2020-08-12 16:02
We?ve had pact implemented in our consumer pipeline (Jenkins) for a few months now, and every so often we get this intermittent error that I cannot seem to reproduce locally at all: ```09:17:35 > jest web/static/scripts/ --runInBand --config jest.pact.js 09:17:35 09:17:38 FAIL web/static/scripts/services/cart/api-cart.service.pact.js 09:17:38 ? Test suite failed to run 09:17:38 09:17:38 TypeError: Cannot read property 'writePact' of undefined 09:17:38 09:17:38 18 | 09:17:38 19 | async teardown() { 09:17:38 > 20 | await this.global.mockServiceProvider.finalize(); 09:17:38 | ^ 09:17:38 21 | this.global.mockServiceProvider = {}; 09:17:38 22 | await super.teardown(); 09:17:38 23 | } 09:17:38 09:17:38 at MockServiceProvider.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) 09:17:38 at CartEnvironment.teardown (web/static/scripts/unit-tests/pact/pactEnvironment.js:20:43) 09:17:38 09:17:38 [2020-08-11T14:17:37.565Z] INFO: pact-node@10.2.4/35469 on http://injkn31a.vpc.zoro.com: 09:17:38 Creating Pact Server with options: 09:17:38 {"consumer":"zoro","cors":false,"dir":"/pub/jenkins/workspace/zoro.com/development/web/static/scripts/unit-tests/pact/pacts","host":"127.0.0.1","log":"/pub/jenkins/workspace/zoro.com/development/web/static/scripts/unit-tests/pact/logs/mockCartServer-integration.log","pactFileWriteMode":"overwrite","port":8921,"provider":"cart-service","spec":2,"ssl":false} 09:17:38 Test Suites: 1 failed, 1 total 09:17:38 Tests: 0 total 09:17:38 Snapshots: 0 total 09:17:38 Time: 0.454s, estimated 10s 09:17:38 Ran all test suites matching /web\/static\/scripts\//i. 09:17:38 [2020-08-11T14:17:37.744Z] INFO: pact-node@10.2.4/35469 on http://injkn31a.vpc.zoro.com: Removing all Pact servers.``` Usually just rerunning the pipeline fixes it, but it?s quite annoying to have this ?non failure? halt development progress. Anyone else run into this?


matt.fellows
2020-08-13 01:02
I have seen this before

matt.fellows
2020-08-13 01:03
from memory, it?s when the mock service hasn?t started properly in the first place (perhaps due to a timeout or otherwise) and because of the way jest/others do the before/after blocks, it shows up at this moment

matt.fellows
2020-08-13 01:03
If you could pop an issue on Pact JS, we should be able to get better state modelling to prevent it trying to do something to an `undefined`

iesmite
2020-08-14 00:40
has joined #pact-js

iesmite
2020-08-14 00:42
Hello!! I'm having some trouble running the pact workshop(https://github.com/pact-foundation/pact-workshop-js), step10 && step11 :disappointed: After the pact is created on consumer and moving to the provider I'm getting this error: ```Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'product with ID 10 exists' for consumer 'FrontendWebsite' at http://localhost:64378/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/iesmite/github/pact-workshop-js/provider/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/iesmite/github/pact-workshop-js/provider/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:76:11)</pre> </body> </html>``` Any idea to help? Thank you!!!

iesmite
2020-08-14 00:43
I installed the modules using npm ci on root and using MacOS catalina

matt.fellows
2020-08-14 00:45
root??

matt.fellows
2020-08-14 00:45
maybe just check that no other processes are running on that port

matt.fellows
2020-08-14 00:46
and just check for rogue npm processes ensuring they?re all shut down

tjones
2020-08-14 00:54
@matt.fellows I think "root" in this context means the root dir of the project, not the root user

iesmite
2020-08-14 01:04
Yep means the root of the process :grinning:

iesmite
2020-08-14 01:05
Sorry the root of the repository

iesmite
2020-08-14 01:07
I'll check that the weird thing is if I remove the utf8 from the content type the problem is unlocked :grinning: I'll send more logs after dinner ; thanks for you help

iesmite
2020-08-14 01:50
now worked when I did with the pacts loaded from file but failing when I tie with a pact broker I will try to debug the node modules and try to get more info

iesmite
2020-08-14 19:46
k was able to fix the issue, adding `--testTimeout=30000` to the jest execution on the provider fixed the problem. Since my broker was remote 5 second wasn;?t enough to run and the log seems to be a weird issue on the express proxy manifested by the iconv-lite encoding loading `{}` and not able to finde the utf-8 decoder. As always the answer was simple that the manifestation of the problem since that problem was raised since that part of the code was executed after jest tests finished by timout.

matt248
2020-08-18 08:27
has joined #pact-js

tjones
2020-08-18 09:32
Hi Pact friends! `jest-pact` v0.8.1 is out. New since 0.7.0: * Support for jest 26 and non-jasmine test runners * More appropriate peer dependencies (all 24.x and 25.x) * Convenience options `logDir` and `logFileName` in case you want to specify only one of those things Each of these improvements was made in response to an issue reported from a user - so thanks are due to cah-timhuddle, Pascal Betting and Alastair Smith. Keep the feedback coming!

damianattademo
2020-08-19 01:49
has joined #pact-js

vladyslav
2020-08-19 08:25
has joined #pact-js

brendan.donegan
2020-08-19 16:13
has joined #pact-js

brendan.donegan
2020-08-19 16:17
Hi. We are trying to add an interaction where there is an ID in the URL that needs to be replaced as the object which the requests acts on needs to be set up by the state handler. The consumer is using pact-js but the provider verification is using Junit and I cannot see any way to update the url. I have seen https://github.com/DiUS/pact-jvm/tree/master/provider/junit#returning-values-that-can-be-injected but it's a bit vague since it just mentions "There are methods on the consumer DSLs that can provider an expression that contains variables" but I can't find anything in the pact-js docs about this.

uglyog
2020-08-19 22:52
This requires V3 Pact support, which vanilla Pact-JS doesn't support (it is V2).


uglyog
2020-08-19 22:54
One thing you could do, is amend the pact file to make it V3 format and add the appropriate matchers and generators to get it to work.

matt.fellows
2020-08-19 23:49
Just confirming that you can?t use the usual provider states to manage this? i.e. setup a state `ID 1234 exists` in the JS test, and have the JVM test ensure ID `1234` exists, such that you can then make a call to a URL with the ID in it without issues

matt.fellows
2020-08-19 23:49
this is definitely the preferred path

tjones
2020-08-20 02:30
> i.e. setup a state ID 1234 exists in the JS test, and have the JVM test ensure ID 1234 exists, ^ this is what I usually do

tjones
2020-08-20 02:31
That approach has the advantage that you can keep the pact file as opaque

brendan.donegan
2020-08-20 08:41
We can't choose the IDs unfortunately, they are generated by the database

brendan.donegan
2020-08-20 08:43
What if we were to update to the Pact JS beta?

florian.nagel
2020-08-20 09:16
has joined #pact-js

brendan.donegan
2020-08-20 09:24
Am I correct in thinking it's not possible to just modify the HttpRequest url, the same as we do for adding additional headers?

jan.krejci
2020-08-20 18:11
has joined #pact-js

iannsantos8
2020-08-20 18:23
has joined #pact-js

uglyog
2020-08-20 21:52
You'll still need a way to get the ID

matt.fellows
2020-08-21 00:21
> What if we were to update to the Pact JS beta? Yes, PactJS v3 doesn?t support URL generation just yet. It?s actually slated for work in the next few weeks, so I?ve just added it to https://pact.canny.io/feature-requests/p/url-generators

brendan.donegan
2020-08-21 08:19
@matt.fellows do you mind if I DM you about this?

matt.fellows
2020-08-21 08:34
Sure. It's just dinner time here but will be online a bit later and I'll do my best to answer

kristine.jetzke
2020-08-21 15:23
has joined #pact-js

ian.letourneau
2020-08-22 14:00
has joined #pact-js

ian.letourneau
2020-08-22 14:32
Hi there! :wave: Sorry if it's already documented somewhere, but I couldn't find the info in the repository. If I want to contribute to the V3 support for pact-js that is currently in beta, where do I start? What is in progress and what are the next steps? Thanks!

uglyog
2020-08-22 23:23
@ian.mcwilliams there is a branch in the pact-js repo -> `feat/v3.0.0`



matt.fellows
2020-08-22 23:25
Master issue to track/comment progress: https://github.com/pact-foundation/pact-js/issues/413

ian.letourneau
2020-08-23 15:37
Thanks @matt.fellows @uglyog!

heytaco
2020-08-25 03:57
has joined #pact-js

heytaco
2020-08-25 03:57
Hi there! My name is HeyTaco!, and you can use me to give people tacos to show your appreciation. My tacos will spread joy through Slack!

tjones
2020-08-25 04:00
I love tacos!

abubics
2020-08-25 04:11
And they love you too, @tjones :taco:

rcrodrigues39
2020-08-25 11:53
has joined #pact-js

rcrodrigues39
2020-08-26 17:59
Hello Pacts! I'? new here and am looking forward to implement a contract test between a consumer (Angular app) and a provider. I found a very nice example with React (https://github.com/pact-foundation/pact-workshop-js), but I was think if we have something similar with Angular?

matt.fellows
2020-08-27 03:27
Not that I?m aware of sorry, but the principles are the same

matt.fellows
2020-08-27 03:28
If someone were to create one? that?d be ace!


matt.fellows
2020-08-27 03:28
If so, I?ll link to it from our site somewhere

tjones
2020-08-27 03:44
The pattern is the same with an angular app - the usual recommendation is to set up the api layer outside Angular, so Pact doesn't need to know about it

matt.fellows
2020-08-27 03:44
Yep

matt.fellows
2020-08-27 03:44
From memory, angular has opinions on the http framework unlike React where it?s a choose your own adventure

matt.fellows
2020-08-27 03:45
but aside from that it?s the same idea

matt.fellows
2020-08-28 02:18
@tjones I can see you and Neezer have been doing a lot of work on the log stuff - awesome! There is a lot of context there that you have, is it OK if I leave that PR with you?

matt.fellows
2020-08-28 02:18
Was picking up a bit of the OSS today to clean up, but given the effort I don?t want to double up if you?ve got it mentally in hand

tjones
2020-08-28 02:42
Yep! Happy to run with it. I'll have some Pact time this weekend too.

matt.fellows
2020-08-28 02:42
Awesome, thanks Tim

tjones
2020-08-28 02:56
@matt.fellows https://github.com/pact-foundation/pact-node/tree/feat/defer-hal-to-clii I noticed this old branch while clearing out merged ones - is it something we might need?

tjones
2020-08-28 03:00
https://github.com/pact-foundation/pact-node/tree/vgrigoruk-fix/consumer_version_tag_array This looks safe to remove as well - I think (and github thinks) it was merged, but it says it is ahead in commits. Maybe we rebased?

matt.fellows
2020-08-28 03:32
yeah, can both go

lewis.prescott
2020-09-03 12:49
has joined #pact-js

lewis.thorley
2020-09-03 15:30
has joined #pact-js

lewis.thorley
2020-09-03 15:31
Does pact-js work on latest version of node? Before I raise an issue I am having with running pact on my new macbook, I just wanted to check

matt.fellows
2020-09-03 22:55
It looks like we don't test against 14 but I've used it on 14. What issues are you having?

tjones
2020-09-04 06:27
Also, I have just updated the builds so that we now test against 14.

lewis.thorley
2020-09-07 07:31
Was completely unrelated to node version in the end. Just needed to increase the jest timeout.

vittorio.guerriero
2020-09-10 12:43
has joined #pact-js

jagiles
2020-09-10 13:19
has joined #pact-js

vittorio.guerriero
2020-09-10 16:33
Hi :wave: . I've noticed that using `@pact-foundation/pact": "^9.6.0"` with the latest broker version (I believe `2.60.1)` is not working correctly when verifying the pacts. I receive the error `Error retrieving` with status `405`. I've tried to update `@pact-foundation/pact` to the latest version and its working. I'm okay to update, I just would like to understand what's the issue and if we can prevent this kind of breaking changes in the future. I'm quite new to pact flow so forgive me if I post it in the wrong channel or If I misunderstood something about the versioning. Let me know if you need any more informations

matt.fellows
2020-09-10 21:41
We normally make things backwards compatible at the broker level so this disturbing. I wonder if it relates to https://pact-foundation.slack.com/archives/C9VPNUJR2/p1599697864045500

matt.fellows
2020-09-11 06:25

vittorio.guerriero
2020-09-11 06:28
Thanks @matt.fellows . Really dumb question. Does pactflow automatically uses the latest version of pact broker?

matt.fellows
2020-09-11 06:29
not a dumb question at all

matt.fellows
2020-09-11 06:29
There is usually a small lag between the OSS version being published and Pactflow using it, but that lag is usually only a few days

matt.fellows
2020-09-11 06:30
you can see what version Pactflow is on by looking at the response headers to any API call, it has the specific OSS version documented so you can check

matt.fellows
2020-09-11 06:31
```x-pact-broker-git-sha: 4a98db4a x-pact-broker-version: 2.60.1```

vittorio.guerriero
2020-09-11 06:33
Thanks. Ive checked. Its using version 2.60.1. I?ll update pact js to the latest version! Thanks for your help

vittorio.guerriero
2020-09-11 07:04
Just to let you know, ive digged into it a bit more, @pact-foundation/pact-node version 10.3.1 fixed the issue. We were using 10.2.4. Not sure if does help. Release changes. https://github.com/pact-foundation/pact-node/compare/v10.2.4...v10.3.1


matt.fellows
2020-09-11 07:11
Appreciate the follow up, I can?t dig into it right this moment I?m afraid but good to know the latest fixes it.

vittorio.guerriero
2020-09-11 07:15
No problem! Have a nice day!

bethskurrie
2020-09-11 08:53
405 is Method not supported.

bethskurrie
2020-09-11 08:55
That version of the ruby standalone was using a beta version of the API that used a GET request. Since then, that API method support has been removed in favour of the POST method that allows structured data. The feature was only officially released out of beta this week.

bethskurrie
2020-09-11 08:59
The API that supports the pending pact, WIP pacts, and consumer version selectors during verification has been officially released. There are some versions of the pact-ruby-standalone (the underlying shared pact code) that use a beta version of the API that is now no longer supported (the original API used a GET, but the parameters turned out to be too complex, so it was changed to a POST). If you find issues, please upgrade to the latest version of your Pact client library.

vittorio.guerriero
2020-09-11 09:05
Thanks @bethskurrie !

jonathanmorley
2020-09-14 17:01
has joined #pact-js

louisallenfrank
2020-09-15 13:45
has joined #pact-js

mcruzdrake
2020-09-17 14:38
Hello :wave: we are currently using pact-js and so far it?s been great but currently our team is facing some limitations for the following use cases: ? expectations for nullable data fields ? expectations for data field which could vary ( unions/interfaces ) Would it be possible if we can go on a call with someone from the Pact team just to explain our uses cases better? Thanks!

tjones
2020-09-17 23:08
So, usually it's best to have two interactions for a nullable field, rather than allow a field to be nullable in the test

tjones
2020-09-17 23:10
this is because if you have a pact where you could say: ```{ someField: SomeComplexObject | null; }``` the test might pass erroneously if the provider could only produce `null`

tjones
2020-09-17 23:15
it's better to specify this in the state: ```state: '<describe whatever condition would cause the field to be null>', willRespondWith: { body: { someField: null } }``` ```state: '<describe whatever condition would cause the field to be present>', willRespondWith: { body: { someField: { /* ...whatever the object would be in a non-null case */ } } }``` does that make sense?

tjones
2020-09-17 23:16
This is a good (and common) question, so it probably highlights that we can make some documentation improvements

tjones
2020-09-17 23:17
The same situation is true for union types - ideally you want to be explicit in the contract, which may result in more than one interaction for successful responses

abubics
2020-09-17 23:38
All the :taco: for @tjones :3

mcruzdrake
2020-09-18 08:27
I see... Okay thanks @tjones for the input, I will pass this on to our team!

tjones
2020-09-18 08:28
You?re welcome. Happy to chat further if you need

mcruzdrake
2020-09-18 08:39
Yes please that would be great. If there's some availability next week for a call that would be really appreciated!

alex.elmekeev
2020-09-18 10:52
has joined #pact-js

alex.elmekeev
2020-09-18 10:54
:wave: https://github.com/pact-foundation/pact-js#pact-js-v3 states that PactJS v3 is not ready for production but all the "not supported" features refers to pacts verification. Does it mean that it's `production-ready` if it's used only on consumer side?

matt.fellows
2020-09-18 11:47
Mmm probably

matt.fellows
2020-09-18 11:47
There are a few rough edges (e.g. types and things need cleaning up)

matt.fellows
2020-09-18 11:47
But it should work

alex.elmekeev
2020-09-18 11:53
ok, will try to give it a try today

thomas.hibbard
2020-09-18 15:49
has joined #pact-js

mui_ume
2020-09-20 05:07
I got an error TypeError: Must provide the pactBroker argument when I run npm run publish:pact, I recalled this was able to run 2 months back. is there any changes? I am running on pact broker docker at http://localhost:9292

matt.fellows
2020-09-20 05:10
The error seems clear. Please share you code because we can't help with what you've provided

matt.fellows
2020-09-20 05:14
See also howtoask

2020-09-20 05:14
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help


matt.fellows
2020-09-20 06:42
I can't see how that property would have ever worked. The type expects `pactBroker` (see https://github.com/pact-foundation/pact-node)


mui_ume
2020-09-20 06:57
thanks I fixed the line at publishPacts.js pactBroker: process.env.PACTBROKERURL, it works now :slightly_smiling_face:

amicicristiano
2020-09-20 14:20
has joined #pact-js

alex.elmekeev
2020-09-21 08:46
``` Cannot find module '../native' from 'node_modules/@pact-foundation/pact/v3/index.js'``` :thinking_face: am I missing something? @matt.fellows

alex.elmekeev
2020-09-21 08:53
9.x works fine for me

matt.fellows
2020-09-21 08:55
What version was failing?

matt.fellows
2020-09-21 08:55
We technically support 10/12/14

alex.elmekeev
2020-09-21 08:55
`10.0.0-beta.15` `node v12.16.2`

alex.elmekeev
2020-09-21 09:25
:wave: I'm moving our js repo from pact-js 8.x to 9/10.x. One of the issues I have is ```Query must only contain strings.``` that is triggered on the interaction with: ``` query: term({ generate: 'limit=50&status=finished&order=desc', matcher: '^limit=[0-9]+&status=(finished)&order=(desc|asc)$', }),``` Are we supposed to use this now: ``` query: { limit: term({ generate: '50', matcher: '[0-9]+', }), status: term({ generate: 'finished', matcher: '(finished)', }), order: term({ generate: 'desc', matcher: '(desc|asc)', }) }```

alex.elmekeev
2020-09-21 09:37
I'm not sure if those are really the same


alex.elmekeev
2020-09-21 11:32
If this change is not an issue how should I write something like ``` query: term({ generate: `filter[id]=${ID}&fields=uuid%2Cgender`, matcher: '^filter\\[(id|first_name)\\]=[^&]+&fields=uuid%2Cgender$', }),``` I would prefer to not have these as separate interactions cause I will have to add 5 of them with essentially the same everything except this first query param.

alex.elmekeev
2020-09-21 11:42
Or this: ```query: term({ generate: 'page=999999&size=1&sort=created,desc', matcher: 'page=999999&size=1(&sort=created,desc|)', }),```

alex.elmekeev
2020-09-21 11:55
Please let me know if you want me to raise an issue for this.


matt.fellows
2020-09-21 12:42
The _values_ of an object should be strings

matt.fellows
2020-09-21 12:42
but the query shouldn?t necessarily be one

matt.fellows
2020-09-21 12:44
But, aren?t you using the new v3 interface?


matt.fellows
2020-09-21 13:02
ah, i didn?t see your reply, sorry

matt.fellows
2020-09-21 13:02
let me quickly look now - otherwise will tomorrow

matt.fellows
2020-09-21 13:07
Do the install logs indicate any form of failure?

matt.fellows
2020-09-21 13:07
2 things come to mind: 1. Pact is in a nested folder or something, and there is bad relative path finding for that module 2. It wasn?t able to download the native module in the first place

alex.elmekeev
2020-09-21 14:27
I see `native` under `node_modules/@pact-foundation/pact` We have yarn with workspaces and this is how structure looks like: ```/ - node_modules - @pact_foundation - pact - native - subproject1 - I run the `jest` here``` Do you think this is related?

alex.elmekeev
2020-09-21 14:29
I see that we already have https://github.com/pact-foundation/pact-js/issues/483. I've added a comment to it.


thomas.hibbard
2020-09-21 16:01
New to Pact. New to Jest. I?m looking for a little help. I see from the `jest-pact` readme that it > Setups Pact mock service before and after hooks so you don?t have to So does that mean I do not have to have a server running to return data. The example sets a base URL to an actual URL, but to just experiment locally, would I need to set up a server at `localhost:3000/health` (and change the `defaultBaseUrl` to that address)? ```const defaultBaseUrl = 'http://your-api.example.com'; export const api = (baseUrl = defaultBaseUrl) => ({ getHealth: () => axios.get(`${baseUrl}/health`).then((response) => response.data.status), /* other endpoints here */ });``` This does seem to be the case, I just want to double-check it isn?t necessary for me to maintain a test server. I?m guessing the `addInteraction` block determines the body that jest-pact?s mock server will return. Also, I note that when I change the xhr of my service to just resolve without any HTTP at all, eg, ```const defaultBaseUrl = 'http://localhost:3000'; export const api = (baseUrl = defaultBaseUrl) => ({ getHealth: () => Promise.resolve('up'), });``` the test fails with > `Pact verification failed!` > `Actual interactions do not match expected interactions for mock MockService.` > `Missing requests:` > `GET /health` Is it necessary to have the actual endpoint in the service so that the jest-pact lib will know to include that in its mock server, or else why would this fail?

matt.fellows
2020-09-21 21:26
Pact starts a mock service which is where you should configure you API client to send it's requests

matt.fellows
2020-09-21 21:26
So you're right, you don't need to start the provider API but jest pact will start one for you

matt.fellows
2020-09-21 21:27
If you don't make the request it will fail, because it checks your code does what you says it does to ensure the contract only has things in it that your client actually needs/uses

ranjanayush03
2020-09-22 08:40
has joined #pact-js

tyler.mehr
2020-09-22 16:59
has joined #pact-js

ranjanayush03
2020-09-23 05:52
Hello.. I was trying to figure on how to set the SSL_CERT_FILE so does this property needs to set in the environment variables of my system or should this be set inside a pact.rb file . Thanks for your help..

matt.fellows
2020-09-23 07:24
It?s an environment variable e.g. `export SSL_CERT_FILE=?`

ranjanayush03
2020-09-23 07:40
ya I tried that but still the same issue , I provided .cer as the file should it be .pem or something like that.

matt.fellows
2020-09-23 09:49
It needs to be an x509 certificate from memory, i'm not sure the extension matters

ranjanayush03
2020-09-23 10:46
Yeah thanks Mat will look into it.

thomas.hibbard
2020-09-23 14:27
Awesome, thank you very much @matt.fellows

begovic.malik
2020-09-23 14:35
has joined #pact-js

begovic.malik
2020-09-24 10:08
Hi all, first time writting in here and I am really new to PACT topic so would really need your help. This is my test case scenario Environment: VueJS Jest PACT I would like to test API that returns me all users /rest/users. My problem is that response body can be empty array, and ofc. array with existing users. Response body looks like this when thare are users in it ```const USERS_DATA = { id: 123, userName: "Test user", userExternalNumber: "0123456789", userInternalNumber: "12" }``` Thing is that I can write test for both case scenarios, one is when provider returns me users with data, and one is when provider returns me a users as empty array. Here are tests: ```test("users exists", async () => { // set up Pact interactions await provider.addInteraction({ state: 'users exist', uponReceiving: 'get all users', withRequest: { method: 'GET', path: '/rest/users' }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: Matchers.eachLike({ id: Matchers.like(123), userName: Matchers.like("Test user"), userExternalNumber: Matchers.like("0123456789"), userInternalNumber: Matchers.like("12") }), }, }); let url = provider.mockService.baseUrl + '/rest/users'; await axios.get(url).then((response => { if(response.data) { if(response.data.length > 0) { expect(response.data[0]).toStrictEqual( {id: 123, userName: "Test user", userExternalNumber: "0123456789", userInternalNumber:"12"}); } } })); }); test("users do not exists", async () => { // set up Pact interactions await provider.addInteraction({ state: 'users do not exist', uponReceiving: 'get all users', withRequest: { method: 'GET', path: '/rest/users' }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: [], }, }); let url = provider.mockService.baseUrl + '/rest/users'; await axios.get(url).then((response => { if(response.data) { expect(response.data).toStrictEqual([]); } })); });``` When I do consumer tests it pass, but problem is when I do provider test, one of those tests will always fail. How to approach this issue?

alex.elmekeev
2020-09-24 10:13
:wave: You should setup you provider to desired state (the one from `state` in your test).

begovic.malik
2020-09-24 10:18
@alex.elmekeev Good point, did not understand (see) that, I found a documentation and will try to solve my problem. Thank you!

matt.fellows
2020-09-24 10:58
There is an e2e example in the project you could use as a basis


begovic.malik
2020-09-24 11:00
@matt.fellows as I manage to understand so far in stateHandlers I need to define different cases and for example in ?users exists? I need to send (create users) and store them in DB? Also in stateHandlers ?users do not exist? I need to delete everything from DB? Am I on correct path?

matt.fellows
2020-09-24 11:01
something like that, yes

begovic.malik
2020-09-24 11:01
ok, thank you, I will keep digging!

matt.fellows
2020-09-24 11:02
Another option as has been stated elsewhere, you could have a single data fixture that knows how to deal with all states (that?s pretty much impossible for empty data sets though, so at the least you?ll need to be able to load/empty a database or replace a DB with an in-memory replacement)

begovic.malik
2020-09-24 11:03
a oke, so to have separate backend instance with all data needed for tests, and then for example if I need to test fetch single user by ID API I would already know in advance what my ID should be?

begovic.malik
2020-09-24 11:10
PS: Another question, Consumer is javascript and for consumer tests I am using pact-js. Backend is JAVA, is it smart to do also provider test then in pact-js?

matt.fellows
2020-09-24 11:11
most people would use Java on the provider side - basically match the language to the code base

matt.fellows
2020-09-24 11:12
Here is a springboot example with Junit that might be helpful: https://github.com/pactflow/example-provider-springboot


begovic.malik
2020-09-24 11:16
Excellent, now I have better understanding of logic behind PACT and also have a lot of material to cover. Thank you again, will stop with questions until I go trough all of this. Wish you a nice day!

matt.fellows
2020-09-24 11:16
hehe you?re welcome

matt.fellows
2020-09-24 11:16
if you have time, highly recommend one of these workshops :point_down:

matt.fellows
2020-09-24 11:16
howtolearn

2020-09-24 11:16
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

begovic.malik
2020-09-24 11:19
Did go with Pact JS workshop and in it I understand relation between consumer -> broker <- provider. Now I am writing my own tests, and will for sure go again to workshop

matt.fellows
2020-09-24 11:44
Release on the way with fix for this @alex.elmekeev (`v9.12.1`) - https://travis-ci.org/github/pact-foundation/pact-js/builds/729923791

matt.fellows
2020-09-24 11:45
thanks for your patience!

artur
2020-09-24 11:49
has joined #pact-js

alex.elmekeev
2020-09-24 12:15
Thank you @matt.fellows! But I think this comment should be https://pact-foundation.slack.com/archives/C9VBGLUM9/p1600680307014400 :slightly_smiling_face: This thread is about issue in v10 beta which is (I guess?) sill not resolved.

matt.fellows
2020-09-24 12:37
Yes, you're right sorry!


thomas.hibbard
2020-09-24 14:26
I have a service I?m testing that calls Angular?s `http.delete` method. Effectively, before I started to write a Pact test for it, it was just throwing away the server response, which was simply a status code of `204` and the body was empty. Within Pact, what is the preferred way to validate a response with an empty body? I can update my `http.delete` method?s options object so that it will return all the HTTP data, including the status code, something like: ```class MyService { deleteItems(config) { return this.http.delete(config.url, { observe: 'response' }) } } /* boilerplate to inject http, instantiate MyService, etc */ await myServiceInstance .deleteItem(deleteItemConfig) .toPromise() .then((response: HttpResponse<Object>) => { expect(response.status).toBe(204); });``` But is this a useful test? Typically I?d be expecting literal body that I put in a matcher, eg a PUT/POST/etc ```const expectedResponse = { some: 'response' } /* pact config */ willRespondWith: { status: 200, body: Matchers.like(expectedResponse) } /* additional pact config */ it('should update a record', async () => { await myService .put(someConfig) .toPromise() .then(response => { expect(response).toEqual(expectedResponse) }) })``` But I?m having trouble understanding what I should do with DELETE/empty response bodies. Has anyone on our channel got any thoughts/preferences?

phil.endsley
2020-09-24 16:29
Does your angular application care about what the response is at all? Is it checking status code or anything? I can tell you how we handle it within our company. As a general rule, we check status codes so we can handle errors explicitly. So our angular services will throw explicit errors for some status codes. For DELETE, the only thing in our contract is that it responds with 204. For the test, we just make sure the service call returns successfully, we don't assert against anything. Since we don't do anything with the response, but we throw errors on "bad" status codes, returning without any thrown errors is good enough for us. This has worked well for us so far, but I'm also curious if anyone is doing anything else

thomas.hibbard
2020-09-24 21:36
I think this is more-or-less what I was leaning toward really, just would have to update that ?response? option in several places. But yeah I?m still super curious to hear others weigh in, since I am still very new to Pact. Thanks for your input @phil.endsley!

tjones
2020-09-24 23:48
Great answer, @phil.endsley :taco:

abubics
2020-09-25 00:08
I completely agree with @phil.endsley :party_parrot:

abubics
2020-09-25 00:10
As an aside, you might want to be wary of responding with a 204 in a ReST API, because it precludes self-describing metadata (along the trajectory to HATEOAS).

thomas.hibbard
2020-09-25 00:28
@abubics How does it preclude self-describing metadata? (Sorry I?m not really following what you mean) Do you mean the server should be transmitting a different code, or there should be supplemental information in the response body? Thanks!

abubics
2020-09-25 02:05
The short version is: rest describes resources, but http responses don't necessarily model resource contents only. One longer rationale is here: https://blog.ploeh.dk/2013/04/30/rest-lesson-learned-avoid-204-responses/

yann.courtel
2020-09-25 12:21
has joined #pact-js

christopher.lampert
2020-09-25 14:53
has joined #pact-js

collin.johnson
2020-09-29 13:58
has joined #pact-js

thomas.hibbard
2020-10-01 14:38
Is there anyway to supply multiple `given`s for a test?

thomas.hibbard
2020-10-01 14:40
I see there is a `state` property, but can i provide many states?

thomas.hibbard
2020-10-01 21:47
It seems the v3 spec has yet to be implemented. Is there any kind of workaround for providing a more complicated data structure to the `state` than just a string?

uglyog
2020-10-01 23:03
You can try the V3 version. It supports multiple givens.

thomas.hibbard
2020-10-01 23:03
@uglyog I get a ts error complaining about giving it an object and it wants just a string.

uglyog
2020-10-01 23:09
Ok, on the given? Is this for the parameters, or the provider state description?

thomas.hibbard
2020-10-01 23:13
On the consumer, I am trying to add an interaction with this code ``` await provider.addInteraction({ state: {}, // compilation error here providerState: {}, uponReceiving: 'a request to load data', withRequest: { method: 'GET', path: `/api/data`, headers: requestHeaders, }, willRespondWith: { status: 200, body: expectedBodyMatcher, headers: responseHeaders, }, });``` > `Type '{}' is not assignable to type 'string'.`

thomas.hibbard
2020-10-01 23:18
`state` works with a string, but not an object. Also:, > Ok, on the given? I don?t have a property called `given` . Is that done in the provider pact code?

tjones
2020-10-02 03:45
By given, do you mean state? Why do you need multiple states?

alex.elmekeev
2020-10-02 12:19
@thomas.hibbard are you using beta version of v3? It's not working for me though: https://pact-foundation.slack.com/archives/C9VBGLUM9/p1600426474003300 multiple states can be useful in some cases when provider needs to seed a number of completely separate entities for you cause state management on their side becomes a bit more readable

thomas.hibbard
2020-10-02 14:34
@alex.elmekeev yeah, I tried the beta and it didn?t work

thomas.hibbard
2020-10-02 17:17
@tjones Sorry I probably worded that poorly. I just need more complex state than a string to mock provider state.

vitaliy.grigoruk
2020-10-02 18:47
we?re still using v2 version and just serializing state object to a string `state: JSON.stringify(stateObject)`

vitaliy.grigoruk
2020-10-02 18:47
@thomas.hibbard ^ it is ugly, but works for us

thomas.hibbard
2020-10-02 18:48
Yeah that was my fallback solution.

thomas.hibbard
2020-10-02 18:48
I note that if I just do like, ```state: { name: `get_data`, data: ['some', 'list', { of: 'stuff' }], } as any``` the compiler won?t complain and it appears to build the pact file correctly.

thomas.hibbard
2020-10-02 18:49
I?m not a ts expert at all though so I?m not sure what the negative consequences of this might be.

thomas.hibbard
2020-10-02 18:49
Any thoughts?

thomas.hibbard
2020-10-02 18:50
@vitaliy.grigoruk

uglyog
2020-10-02 23:42
Just remember that with TS, it is basically JS with types added. But objects are still plain JS objects in the end. What you're doing is just telling the compiler that that object has no specific type, i.e., it is just a plain JS object.

uglyog
2020-10-02 23:43
You just loose the ability of TS to tell you if you have the correct attributes on the object.

tjones
2020-10-04 23:10
@thomas.hibbard: I wouldn't recommend using `as any`, as Ron says, you lose the ability for the compiler to check that you're using the correct types (which isn't the case here, because provider state is meant to be a string). If it's working, I think it's a coincidence with how the unmarshalling works once it gets into Ruby land. There's no special or additional processing of the state in pact-js

nazar.khmil
2020-10-05 10:34
has joined #pact-js

xandebianchi
2020-10-05 13:05
has joined #pact-js

thomas.hibbard
2020-10-05 14:38
And anyway the broker seems unable to parse the file :disappointed:

dorin.enache
2020-10-05 15:01
has joined #pact-js

thomas.hibbard
2020-10-05 15:14
But I guess I don?t really understand what the big deal is with overriding the type. It?s not like I do anything with the `state` property after I add my interaction, and I am _just_ doing the `as any` on the `state` property, not the entire `addInteraction` config object. I mean it?s all a little academic because, as I say, the broker seems unable to parse it so I guess strings will have to do :wink: but thanks guys for the feedback!

ruth
2020-10-05 18:53
has joined #pact-js

ruth
2020-10-05 18:55
Hi! My tests on the provider side is silently failing and Im not sure why

ruth
2020-10-05 18:55
I wonder if its my configurations, was wondering if anyone would have insight

rcrodrigues39
2020-10-05 21:52
@ruth do you have any error logs? If so, would you mind sharing them here so we can have a better idea of what the problem could be?

ruth
2020-10-05 21:56
Hey! Thanks for responding! I actually got it to work. I had to use `async/await` so it waited till it was finished. Then used `publishVerificationResult: false` so I wouldnt seen any unnecessary information

ruth
2020-10-05 21:57
The one thing I also did was `enablePending: false` so I could see pending tests which was very weird because I would assume `enablePending` when `true` would mean you can run tests that are pending but it looked like that wasnt the case.

uglyog
2020-10-05 23:36
I think we don't really understand what you're trying to do. I assume you have tried to use a JS object in place of the string value for the state? If this is the case, it will not work properly because it will get serialised to a string in the resulting Pact file.

uglyog
2020-10-05 23:37
If you use the V3 beta version of Pact-JS instead, you can use the `given` method which allows structured data to be associated with the state description as parameters.


uglyog
2020-10-05 23:39
For current Pact-JS (9.x), you will need to use `JSON.stringify` so that the object can be serialised correctly, but that would need to then be parsed on the other end

tjones
2020-10-05 23:39
If you're not using the V3 beta, the usual workaround is to use a string for state: ```state: JSON.serialise({ name: `get_data`, data: ['some', 'list', { of: 'stuff' }], })``` Note that you will need to deserialise the string in your provider code

matt.fellows
2020-10-05 23:40
He?s right though - you can literally put anything into state and it does get serialised into the pact file as properly structured JSON - and it comes out the other side too (there is a WIP PR that Honza created that does exactly this)

matt.fellows
2020-10-05 23:40
I haven?t merged it, because I?m not sure it?s the ?right thing?

tjones
2020-10-05 23:41
Pact-JS just passes it off to the ruby binary via http.

matt.fellows
2020-10-05 23:41
yep

matt.fellows
2020-10-05 23:41
I don?t want to encourage it though, because it?s more undefined behaviour that is incidentally helpful, but is likely to stop working

brendan.donegan
2020-10-06 09:45
Hi - we?re using jest-pact (which is fantastic) for writing our consumer tests, but we are now trying to add a test which uses Pact V3. I can?t seem to see any way to make jest-pact use v3 functionality. I?m guessing I probably need to write the test in raw Jest and use PactV3 directly?

yousafn
2020-10-06 10:21
Hey @brendan.donegan if you create an issue on jest-pact, I have a feeling that @tjones might have created a branch for it

brendan.donegan
2020-10-06 10:30
done

tjones
2020-10-06 10:33
I haven?t, but I?m happy to chat about what such a branch might look like, since you?re not the first person to ask this

tjones
2020-10-06 10:33
(I haven?t yet used v3 myself)

yousafn
2020-10-06 10:33
Cheers squire :slightly_smiling_face:

yousafn
2020-10-06 10:33
Me neither, but hearing good things!

brendan.donegan
2020-10-06 10:34
@tjones sure, maybe i can help take a look at that?

tjones
2020-10-06 10:41
That would be excellent! I'm just taking a look at the V3 branch now to see what would be useful

tjones
2020-10-06 10:42
Last time I checked, the API was a bit different, so the setup and teardown thing might not be so useful

tjones
2020-10-06 10:42
my gut is that it would be nicest to be able to say `import { pactWith } from 'jest-pact/v3';`

tjones
2020-10-06 10:49
Also, while I've got you - I'm keen to hear from Pact-JS (and jest-pact) users about how you're doing your config. I'd like to improve the way pact-js gets its config

tjones
2020-10-06 10:50
I'm thinking it might make sense to have a `pact` key in `package.json`, which allows specifying some of the things that would be in every pact config in each test.

tjones
2020-10-06 10:58
Looks very straight forward to add V3...

brendan.donegan
2020-10-06 10:59
cool

tjones
2020-10-06 11:00
Ah, of course. We can't import V3 in standard jest-pact because of peer deps. It'll have to be a separate release.

brendan.donegan
2020-10-06 11:08
that won?t prevent us from using both v3 and v2 in the same project? i mean i could upgrade all our tests to v3 i suppose

tjones
2020-10-06 11:15
I believe you'll be ok, because the V3 branch includes V2

tjones
2020-10-06 11:16
Hm. There's an annoying property where we can't inject the provider as easily, because it needs to be remade on each test

tjones
2020-10-06 11:18
more thought around the API needed. I haven't written any V3 tests yet, so I'm not sure what would be nice

tjones
2020-10-06 11:18
I'll make some sketches just now - but input is very welcome

tjones
2020-10-06 11:32
```pactWith(options, (pactDescribe) => { pactDescribe('some interaction', (provider) => { beforeEach(() => provider .given('Some state') .uponReceiving('Some request') .withRequest({ path: '/whatever/path', method: 'GET' }), ); it('works', () => provider .executeTest((mockserver) => api(mockserver.url).getWhatever()) .then((response) => { expect(response).toEqual({ whatever: 'it-should-be' }); })); }); });```

tjones
2020-10-06 11:33
Something like that, maybe?

brendan.donegan
2020-10-06 12:16
that looks good to me

brendan.donegan
2020-10-06 12:17
only curious why we need to inject pactDescribe?

tjones
2020-10-06 12:17
it remembers the options

tjones
2020-10-06 12:17
I've got something a little cleaner

tjones
2020-10-06 12:19
```pactWith(options, (interaction) => { interaction('some interaction', ({ provider, execute }) => { beforeEach(() => provider .given('Some state') .uponReceiving('Some request') .withRequest({ path: '/whatever/path', method: 'GET' }), ); execute('some api call', (mockserver) => api(mockserver.url) .getWhatever() .then((response) => { expect(response).toEqual({ whatever: 'it-should-be' }); }), ); }); });```

tjones
2020-10-06 12:19
unsure on the names

tjones
2020-10-06 12:20
but this one has the advantage that it is implemented

tjones
2020-10-06 12:20
(just working on publishing)

tjones
2020-10-06 12:22
The implementation is a bit raw, but it should work and will help us discover what the interface should be

tjones
2020-10-06 12:23
I nearly injected custom functions like this for the original jest-pact - I thought it might help people remember to return promises.

tjones
2020-10-06 12:24
I think the `{ provider , execute }` thing could be improved too, abstracting the beforeEach. Maybe. I'm not really sure what's best.

tjones
2020-10-06 12:25
This exercise has highlighted that V3 is missing the object interaction description method

ledinhcuong99
2020-10-06 12:53
has joined #pact-js

matt.fellows
2020-10-06 13:05
description?

matt.fellows
2020-10-06 13:07
do you mean `uponReceiving`?

tjones
2020-10-06 13:15
@brendan.donegan You can now get the V3 interface as above with ```npm install --save-dev jest-pact@0.9.0-beta.v3``` Try it out and see if it works for you. I'd like to consider the interface non-final until a few people have had a play with it. I'm conscious that the original jest-pact was based off a pattern we developed after writing a lot of tests, and this interface is just based on what I thought would work.

tjones
2020-10-06 13:17
@matt.fellows Sorry, I wasn't clear. In the current pact-js, you can add interactions by creating an interaction and using the `.given().uponReceiving()` methods, or by passing a config object that describes everything in the interaction. For ease of conversion to V3, I think we should support both.

matt.fellows
2020-10-06 13:19
gotcha

matt.fellows
2020-10-06 13:19
Amazing stuff Tim!!

matt.fellows
2020-10-06 13:39
@tjones please enjoy a midnight :taco: (why are you up so late?)

tjones
2020-10-06 13:39
practice :wink:

matt.fellows
2020-10-06 13:39
Heck, @tjones have _another_ taco. This time with :tomato: sauce (really!? no :sauce: emoji??)

matt.fellows
2020-10-06 13:39
_nods_

matt.fellows
2020-10-06 13:40
also, daylight savings

ruth
2020-10-06 13:40
hey quick question

matt.fellows
2020-10-06 13:41
Hopefully quick, because I?m in the same TZ as Tim and very shortly my wife will be forcing me off this computer :stuck_out_tongue:

matt.fellows
2020-10-06 13:41
(or pointing me at the couch)

ruth
2020-10-06 13:41
Im using pact in typescript and when import using this `const { Verifier } = require('@pact-foundation/pact');` everything is all good. But when I use `import { Verifier } from '@pact-foundation/pact';` it gives me a typing error

tjones
2020-10-06 13:41
Something I've wanted to do for a while is to automatically get the test name from jest (but you can't). It could be good to swap: ``` beforeEach(() => provider .given('Some state') .uponReceiving('Some request') .withRequest({ path: '/whatever/path', method: 'GET' })``` for ``` setupInteraction("Some request", provider => provider .given('Some state') .withRequest({ path: '/whatever/path', method: 'GET' }) ``` We could do a similar thing with the base jest-pact pretty easily.

ruth
2020-10-06 13:42
```import { Verifier } from '@pact-foundation/pact'; ... const opts = { provider: 'tpt-education-standards', providerBaseUrl: 'http://localhost:3000', pactBrokerUrl: 'https://tpt.pactflow.io', pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: false, providerVersion: '1.0.0', consumerVersion: '1.0.0', enablePending: false, logLevel: 'info', includePendingStatus: true, stateHandlers: { 'I have a standard': () => { // TODO: provider state is handler in beforeAll hook }, 'I have a jurisdiction': async () => { // TODO: provider state is handler in beforeAll hook } } };```

ruth
2020-10-06 13:42
``` Argument of type '{ provider: string; providerBaseUrl: string; pactBrokerUrl: string; pactBrokerToken: string | undefined; publishVerificationResult: boolean; providerVersion: string; consumerVersion: string; enablePending: boolean; logLevel: string; includePendingStatus: boolean; stateHandlers: { ...; }; }' is not assignable to parameter of type 'VerifierOptions'. Type '{ provider: string; providerBaseUrl: string; pactBrokerUrl: string; pactBrokerToken: string | undefined; publishVerificationResult: boolean; providerVersion: string; consumerVersion: string; enablePending: boolean; logLevel: string; includePendingStatus: boolean; stateHandlers: { ...; }; }' is not assignable to type 'ProxyOptions'. Types of property 'logLevel' are incompatible. Type 'string' is not assignable to type '"info" | "trace" | "debug" | "warn" | "error" | "fatal" | undefined'```

ruth
2020-10-06 13:43
Im not sure why its not understanding that ?info? is the part of the LogLevel type. It keeps saying my input is a string when its clear that its one of the options.

tjones
2020-10-06 13:43
Oh yeah. Sorry about this one. It's because the type is an enum.

ruth
2020-10-06 13:43
Sorry for keeping yall up!

matt.fellows
2020-10-06 13:44
I think we do expose an enum for that

tjones
2020-10-06 13:44
We dooo, but I don't think it has been exposed at the root.

matt.fellows
2020-10-06 13:44
ah


ruth
2020-10-06 13:44
so I cant import it that way then

matt.fellows
2020-10-06 13:44
ah yes, nice idea

tjones
2020-10-06 13:45
```import { LogLevel } from '@pact-foundation/pact/dsl/options';```

matt.fellows
2020-10-06 13:45
ugly

tjones
2020-10-06 13:45
This will work, but I don't like it, because what if we move it

tjones
2020-10-06 13:45
I think I'll just go release a fix that exports it at the root.

matt.fellows
2020-10-06 13:45
Easily fixed from our side.

matt.fellows
2020-10-06 13:45
thx

ruth
2020-10-06 13:45
Thank you!!!

matt.fellows
2020-10-06 13:45
did you want Ruth to raise an issue?

tjones
2020-10-06 13:46
Nah, I'll just fix it now.

matt.fellows
2020-10-06 13:46
You have my blessings to ship it without a PR :white_check_mark: approval. Pre approval!

ruth
2020-10-06 13:46
Yall are awesome I appreciate it!

tjones
2020-10-06 13:46
I've been meaning to do it for a while, because we have the same potentially brittle import in jest-pact

matt.fellows
2020-10-06 13:47
_nods_

matt.fellows
2020-10-06 13:47
you are a gentleman and a scholar (I think literally, right?!)

matt.fellows
2020-10-06 13:47
good night y?all :stuck_out_tongue:


tjones
2020-10-06 13:49
Sleep well, Matt!

thomas.hibbard
2020-10-06 14:22
> If you use the V3 beta version of Pact-JS instead, you can use the `given` method which allows structured data to be associated with the state description as parameters. @uglyog The documentation is pretty explicit about not using this in a production env though. Do you think it?s okay?

tjones
2020-10-06 14:22
@ruth I've just released 9.12.2 which exports the types you need at the root. You can then say `logLevel: http://LogLevel.Info,` in your config object.

tjones
2020-10-06 14:24
Also don't listen to GitHub. I released 9.12.2, not Matt :stuck_out_tongue:

thomas.hibbard
2020-10-06 14:24
> I think we don?t really understand what you?re trying to do. I?m just trying to pass a data structure more complex than a string to my producer code, like seems should be available in the Pactv3 spec

tjones
2020-10-06 14:24
....we should fix that

ruth
2020-10-06 14:24
Ill test it out now :slightly_smiling_face:

tjones
2020-10-06 14:26
At the moment, the best way is to marshal any complex type to a string (and back again).

ruth
2020-10-06 14:26
That worked but there are new typing issues. What Ill do is checkout what other typing issues are happening and raise an issue. What is the process to raise an issue?

ruth
2020-10-06 14:27
Also you should go to bed its probably really late for yall

tjones
2020-10-06 14:27
Given the recent uptick in interest in the V3 spec, I think we'll put some concentrated effort into sorting out the remaining V3 spec tasks so it is prod ready.

tjones
2020-10-06 14:27
(especially given that it's Hacktoberfest)


thomas.hibbard
2020-10-06 14:29
Awesome. Stringification is fine for now, but I know my producer-writers are using V3 so yeah it would be awesome to be in lockstep with them. Thanks again.

tjones
2020-10-06 14:29
No worries. I'll take a look in the morning - should hopefully be an easy fix. If you need to import things directly, the folder structure doesn't change often. However, I wouldn't want to rely on it (on my loose todo list is to refactor a bit so the types are easier to reason about internally).

brendan.donegan
2020-10-06 14:30
@tjones this is great, thanks!

tjones
2020-10-06 14:31
You're welcome! I'm heading to bed here, but I'll check back tomorrow for any feedback.

tjones
2020-10-06 14:37
Just quickly, you have `consumerVersion: '1.0.0',`, which I don't think is the right option. You might want: ```consumerVersionSelectors: { pacticipant: 'consumer name goes here', version: '1.0.0' }``` but you probably want to remove it entirely (or use `latest` or another tag)

tjones
2020-10-06 14:38
Similarly I don't think `includePendingStatus` is valid - you might have meant `enablePending`

tjones
2020-10-06 14:39
(also if those properties were copied from an example, let us know which one and we'll correct it)

ruth
2020-10-06 15:46
@tjones Thank you! and everything works :relaxed: The example I was going by was this: https://github.com/pactflow/example-provider/blob/e7cd82fe146a04513ddb41b57e537f00774e0415/src/product/product.pact.test.js#L18 I figured I needed to also add a consumerVersion not realizing looking down that I needed to actually look at https://github.com/pactflow/example-provider/blob/e7cd82fe146a04513ddb41b57e537f00774e0415/src/product/product.pact.test.js#L31 My assumption is that it automatically goes to `latest` so Ill just remove it entirely.

ruth
2020-10-06 15:54
I figured out why the typing was a bit of. I needed to do this: So I created a constant (`LOGLEVEL_INFO` ) that?s type is `LogLevel` so that the constant is an `Enum` and I can use it in the `opts` object ```import { LogLevel, Verifier } from '@pact-foundation/pact'; ... const LOGLEVEL_INFO: LogLevel = 'info'; const opts = { provider: 'tpt-education-standards', providerVersion: '1.0.0', providerBaseUrl: 'http://localhost:3000', pactBrokerUrl: 'https://tpt.pactflow.io', pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: false, enablePending: true, logLevel: LOGLEVEL_INFO, stateHandlers: { 'I have a standard': async () => { // TODO: provider state is handler in beforeAll hook }, 'I have a jurisdiction': async () => { // TODO: provider state is handler in beforeAll hook } } };```

matt.fellows
2020-10-06 23:11
> @uglyog The documentation is pretty explicit about not using this in a production env though. Do you think it?s okay? Sorry for confusion here @thomas.hibbard. It?s actually production ready in the sense that all of the matching works, it?s integration with the pact broker that needs a little work (see https://github.com/pact-foundation/pact-js/issues/413 for the master tracking issue)

uglyog
2020-10-06 23:18
That was added by @bethskurrie when she went on a mad tangent and put that to tell everyone not to use it. But if nobody uses it, we won't ever get the feedback needed to improve it to useable state to be able remove the warning to not use it.

tjones
2020-10-06 23:23
Yes, that will work. If you want a slightly shorter version, you can also tell typescript that the `opts` is a `VerifierOptions`: ```const opts: VerifierOptions = { logLevel: 'info', ....``` Apologies for steering you wrong before - I thought we had an enum and not a string literal type. String literal types are an annoying part of typescript because the compiler gets confused unless you're explicit.

ruth
2020-10-06 23:26
No worries! I didnt see the `VerifierOptions` type, will refactor to use that then. :slightly_smiling_face:

brendan.donegan
2020-10-07 07:54
so, i?m getting an error of a kind i?ve never seen before and there are no logs being created?

brendan.donegan
2020-10-07 07:54
```Test failed for the following reasons: Test code failed with an error: Cannot read property 'matches' of undefined Mock server failed with the following mismatches: 1) QueryMismatch Unexpected query parameter 'assignmentTitle' received 2) QueryMismatch Unexpected query parameter 'studentAssignmentId' received 3) QueryMismatch Unexpected query parameter 'studentAssignmentStatus' received 4) QueryMismatch Unexpected query parameter 'assignmentDueDate' received 5) QueryMismatch Unexpected query parameter 'activityId' received```

brendan.donegan
2020-10-07 07:55
maybe i need to define the query differently?

tjones
2020-10-07 07:55
Hmm. What have you got?

matt.fellows
2020-10-07 07:55
How are you doing it now?

brendan.donegan
2020-10-07 07:55
I just pass a string key=value&key2=value2 etc

matt.fellows
2020-10-07 07:56
v3 pact changes the way it deals with query strings (it internally represents them as a map of string keys to values (`[]`)

matt.fellows
2020-10-07 07:56
so is that your http client doing that, or how you define it in the pact test?

brendan.donegan
2020-10-07 07:56
```.withRequest({ method: 'GET', path: `${API_URL}/${RESOURCE_ID}`, query: QUERY_STRING_PARAMS, headers: new Headers({ Accept: 'application/json', 'Content-Type': 'application/json', Authorization: 'sif', }), })```

brendan.donegan
2020-10-07 07:57
```const QUERY_STRING_PARAMS = 'studentAssignmentId=308983e7-3a84-40e1-9596-6fb44217f39c&activityId=bd37478f-a6c7-440f-8593-d6a20304db7f&studentAssignmentStatus=NOT_STARTED&assignmentTitle=QA+Test+19+Jun+2020+12%3A10%3A24+-+eBookTestData+Student+Dashboard+Due+Today+-+Print+Student+Edition+PDF%3A+HMH+Science+Dimensions%3A+Grade+5&assignmentDueDate=2020-06-19T22%3A59%3A59.000Z';```

matt.fellows
2020-10-07 07:57
aha

brendan.donegan
2020-10-07 07:57
should ?query? be an object?

matt.fellows
2020-10-07 07:58
that may be it, let me check to see how the new API is designed

matt.fellows
2020-10-07 07:58
I think so


tjones
2020-10-07 07:59
The old DSL supports both. I think the new one should too.

matt.fellows
2020-10-07 07:59
so more like: ```query: { "studentAssignmentId": [3089], ... }```

matt.fellows
2020-10-07 07:59
yes probably

matt.fellows
2020-10-07 08:00
I?ve been updating the Golang lib recently over time to support v3 and have been careful to add backwards compatibility for these things

matt.fellows
2020-10-07 08:00
one thing I found is that ? query string behaviour is very framework dependent. but that?s a whole other thing

tjones
2020-10-07 08:00
Also looks to me like query string doesn't support arrays or matchers in V3

matt.fellows
2020-10-07 08:00
for now, you?ll need to convert into that object format

matt.fellows
2020-10-07 08:01
well, it supports arrays because the key value _must_ be an array

tjones
2020-10-07 08:01
```export interface V3Request { method: string path: string query?: { [param: string]: string } headers?: { [header: string]: string } body?: any }```

matt.fellows
2020-10-07 08:01
but it doesn?t appear to support matchers, true. At least, the type definition belies it

brendan.donegan
2020-10-07 08:02
well it works now :smile:

matt.fellows
2020-10-07 08:02
There is an issue relating to the type definitions - I think you _can_ put matchers in things that based on their type, you wouldn?t think you could

matt.fellows
2020-10-07 08:03
sorry yes, Tim and I are looking from a different perspective. Good to hear it?s up and going though :stuck_out_tongue:

brendan.donegan
2020-10-07 08:07
@matt.fellows now i?m just trying to update this test to integrate the url generator. I followed the example you sent me but it fails and doesn?t give very much information

brendan.donegan
2020-10-07 08:08
ignore me. typo (i think)

brendan.donegan
2020-10-07 08:09
there was a typo, but it still fails

brendan.donegan
2020-10-07 08:09
I defined path like this now: ```path: regex( `${API_URL}/\\w+`, `${API_URL}/11112222-3333-4444-5555-66666666`, ),```

tjones
2020-10-07 08:11
I'm nervous about that definition of path

brendan.donegan
2020-10-07 08:13
i think my regex is probably wrong

brendan.donegan
2020-10-07 08:13
it wants to match a UUID

brendan.donegan
2020-10-07 08:14
@tjones any idea where the logs might be now?

tjones
2020-10-07 08:17
I think there are no logs (apologies, I haven't been involved with the v3 work, so I only started looking at it last night)

tjones
2020-10-07 08:18
So, usually what I do is not put matchers in the request, because you want to make sure that the test is "When I ask for X, the provider receives a request for X", and not "the provider receives some kind of valid request"

tjones
2020-10-07 08:20
If for some reason you need this, then it is supported, but I'm not sure if it's supported by V3 yet

brendan.donegan
2020-10-07 08:20
yep, this conversation has been had - it?s been added :slightly_smiling_face:

matt.fellows
2020-10-07 08:20
sorry I?m just making dinner etc. Is this the example you?re looking at https://github.com/pactflow/example-siren/blob/master/consumer/src/__tests__/delete-order.spec.js ?

brendan.donegan
2020-10-07 08:21
yes

matt.fellows
2020-10-07 08:22
ok ta

matt.fellows
2020-10-07 08:22
For reference, Tim, this is the canny ticket: https://pact.canny.io/feature-requests/p/url-generators

matt.fellows
2020-10-07 08:23
Brendan, are you using the `url` generator or the `regex` matcher (what I can see above)? Or are they separate problems you?re running into?

brendan.donegan
2020-10-07 08:23
unfortunately we need to put uuid?s generated by our database in the url

matt.fellows
2020-10-07 08:26
no that?s OK. I noticed that you used the `regex` above but we?re talking about generators, just trying to clarify your example

brendan.donegan
2020-10-07 08:27
i?m not using the `url` generator. i didn?t notice that

matt.fellows
2020-10-07 08:28
I?m confused. I thought you wanted the URL generator :laughing:

brendan.donegan
2020-10-07 08:28
i think i?m the one who?s confused :slightly_smiling_face:

matt.fellows
2020-10-07 08:28
:slightly_smiling_face:

matt.fellows
2020-10-07 08:30
So let?s start fresh (and then I _really_ gotta run :grimacing: ) 1. You have a provider that has UUIDs for IDs so you can?t use a provider state, because they are generated 2. Your consumer just needs to be able to send a message to path with a UUID in it (can be any, but you?ll use a regex to match it) 3. ON the provider side, you need to be able to dynamically substitute in the UUID, right? @uglyog will be able to clarify if the new feature does this. I fear I may have steered you in the wrong direction

brendan.donegan
2020-10-07 08:31
that?s all correct

dothetan.040490
2020-10-07 09:14
has joined #pact-js

brendan.donegan
2020-10-07 19:32
Just wanted to follow up on this. I?m still kind of none the wiser. Is url() the correct construct to use for the path?

waquino
2020-10-07 21:43
Hi, i?m having an issue where the verifications result are not been publish to the broker

waquino
2020-10-07 21:43
not error just not publishing the results

waquino
2020-10-07 21:43
```[2020-10-07T21:04:53.645Z] INFO: pact-node@10.8.1/41 on 744ea855f640: Verifying Pact Files PASS src/cats.controller.pact.test.ts (7.707s) Pact Verification verify the provider ? should verify the provider (1902ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 7.764s Ran all test suites matching /.pact.test.ts$/i. [2020-10-07T21:04:55.491Z] INFO: pact-node@10.8.1/41 on 744ea855f640: Pact Verification succeeded. console.log src/cats.controller.pact.test.ts:73 Verification Ran```

waquino
2020-10-07 21:43
is there any place where i should look for that error?

waquino
2020-10-07 21:45
it has the publishVerificationResult set to true

matt.fellows
2020-10-07 21:47
can you please share your pact test? Are you fetching the pacts from the broker or using local files?

waquino
2020-10-07 21:47
from the broker

waquino
2020-10-07 21:48
```describe('Pact Verification', () => { let catsController: CatsController; let catService: CatService; const pactBrokerUrl = process.env.PACT_BROKER_URL || 'http://localhost:8080'; const pactBrokerUsername = process.env.PACT_BROKER_USERNAME || 'user'; const pactBrokerPassword = process.env.PACT_BROKER_PASSWORD || 'pass'; const providerVersion = process.env.PROVIDER_VERSION || '1.0.0'; const providerUrl = process.env.PROVIDER_URL || "http://localhost:3050"; let publishVerification = true; if(process.env.PUBLISH_VERIFICATION ){ publishVerification = true; } const catExample: Cat = { 'name': 'cat', 'age': 12, 'breed': 'angora', 'color': 'orange' }; const providerBrokerOpts = { logLevel: "trace", providerBaseUrl: providerUrl, pactFilesOrDirs: ['./pacts/'], pactBrokerUrl: pactBrokerUrl, pactBrokerUsername: pactBrokerUsername, pactBrokerPassword: pactBrokerPassword, provider: 'catsProvider', enablePending: true, verbose:true, publishVerificationResult: publishVerification, providerVersion:providerVersion, consumerVersionTag: ['prod', 'test'], stateHandlers:{ 'I have a single cat with color': ()=>{ return Promise.resolve(catExample); }, 'I have a single cat object with color': ()=>{ return Promise.resolve(catExample); } } }; beforeEach(async ()=> { const moduleRef: TestingModule = await Test.createTestingModule({ controllers: [CatsController], providers: [CatService], }).compile(); catsController = await moduleRef.resolve(CatsController); catService = moduleRef.get<CatService>(CatService); console.log(pactBrokerUrl); console.log(pactBrokerPassword); console.log(pactBrokerUsername); console.log(providerVersion); }); describe('verify the provider', () => { it('should verify the provider', async () => { return new Verifier(providerBrokerOpts).verify().finally(() => { console.log('Verification Ran') }); }); }); })```

waquino
2020-10-07 21:49
```? npm run test:pact > pact-provider@0.0.1 test:pact /Users/wellingtonaquino/Documents/wiser-repo/pact-nestjs-provider-sample > jest ".pact.test.ts$" console.log src/cats.controller.pact.test.ts:63 http://localhost:8080 console.log src/cats.controller.pact.test.ts:64 user console.log src/cats.controller.pact.test.ts:65 pass console.log src/cats.controller.pact.test.ts:66 1.0.0 [2020-10-07T21:41:56.223Z] INFO: pact-node@10.8.1/53691 on Wellingtons-MacBook-Pro.local: Verifying Pact Files PASS src/cats.controller.pact.test.ts Pact Verification verify the provider ? should verify the provider (846ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 3.476s, estimated 7s Ran all test suites matching /.pact.test.ts$/i. [2020-10-07T21:41:57.025Z] INFO: pact-node@10.8.1/53691 on Wellingtons-MacBook-Pro.local: Pact Verification succeeded. console.log src/cats.controller.pact.test.ts:73 Verification Ran```

matt.fellows
2020-10-07 21:50
is `PUBLISH_VERIFICATION` definitely set?

matt.fellows
2020-10-07 21:50
maybe comment that out and hard code it to `true`


waquino
2020-10-07 21:51
i even removed the variable and set it manually

matt.fellows
2020-10-07 21:51
`pactFilesOrDirs` is set - is that intended?

uglyog
2020-10-07 21:53
To enable logging, set the LOG_LEVEL environment variable.

waquino
2020-10-07 21:53
is set to pactFilesOrDirs: [?./pacts/?],

matt.fellows
2020-10-07 21:54
yes, don?t do that. The pacts won?t being fetched from the broker if you do that, and therefore won?t have verification results

uglyog
2020-10-07 21:54
Regex on path should work, set LOG_LEVEL=debug and you will see what is being matched and how

waquino
2020-10-07 21:56
if i remove it i get the same :disappointed:

matt.fellows
2020-10-07 21:56
Ron, see point above. Is it fair to say that the new `url` feature won?t actually address Brendan?s needs?

uglyog
2020-10-07 21:58
Yes, `url` was not designed to work with paths, it expects a full URL. Regex should work with paths

matt.fellows
2020-10-07 21:58
Can you please share a reproducible code sample? THis code definitely works, because I ran a demo this morning doing it (see our example consumer/provider)

matt.fellows
2020-10-07 21:58
my guess is that your consumer version tags don?t actuallly match up (i.e. your checking for `prod` and `test` but I can?t see the tags on the broker)

matt.fellows
2020-10-07 21:58
have you published the contract AND tagged with `prod` or `test`?

matt.fellows
2020-10-07 21:59
It actually doesn?t appear to be verifying any pacts

uglyog
2020-10-07 21:59
We should have a way of tracking all the improvements, like supporting string query parameters.

uglyog
2020-10-07 21:59
I'll create a GH issue, unless we have a better way

matt.fellows
2020-10-07 22:00
regex won?t work on the provider side though. He needs the generator feature > We should have a way of tracking all the improvements, like supporting string query parameters. hmm, something like a github issue? ;)

matt.fellows
2020-10-07 22:00
He needs the ?injecting provider states? in the URL feature, I think

waquino
2020-10-07 22:01
i added the pact as part of the contract

waquino
2020-10-07 22:01
not sure how to validate that part on the published version

uglyog
2020-10-07 22:01
Ah, yeah, that has not been exposed to the consumer DSLs yet

waquino
2020-10-07 22:05
i know it worked for me before, i?m going to retry from scratch or create a reproducible flow

waquino
2020-10-07 22:05
and let you thanks for the quick response

matt.fellows
2020-10-07 22:08
thx, I?ll raise that too

matt.fellows
2020-10-07 22:08
Brendan - let?s chat. Apologies for any confusion

matt.fellows
2020-10-07 22:51
If you could share your publishing code, I could help you out

matt.fellows
2020-10-07 22:51
but TL;DR - make sure tags on consumer and provider side align, otherwise the verifier may not catch the pacts you want to verify

matt.fellows
2020-10-07 22:52
Also do the CI/CD workshop in howtolearn

2020-10-07 22:52
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

dagostino.remy
2020-10-07 23:03
has joined #pact-js

waquino
2020-10-07 23:30
the consumer has the tags, but is not publishing those

waquino
2020-10-07 23:30
tags are just latest

waquino
2020-10-07 23:34
if i add latest

waquino
2020-10-07 23:34
it pick it up

waquino
2020-10-07 23:36
thanks : :blush:

matt.fellows
2020-10-07 23:40
Ah, _don?t_ use latest - that?s an anti-pattern. Use something like `main` or `development` . Latest has a special meaning

matt.fellows
2020-10-07 23:40
but good to hear it works!

waquino
2020-10-07 23:41
yes updated the consumer

waquino
2020-10-07 23:42
the issue was that i defined the tags while creating the pacts but not while publishing

matt.fellows
2020-10-07 23:45
what do you mean by ?while creating the pacts??

waquino
2020-10-07 23:55
i?ve created to different task to run ?publish:pact?: ?node publish.js?, ?test:pact?: ?jest \?.pact.test.ts$\??,

waquino
2020-10-07 23:55
publish.js just takes all the pacts an publish to the broker

matt.fellows
2020-10-07 23:56
but you mentioned that you were tagging when creating the pacts, but not publishing - what does that mean sorry?

waquino
2020-10-07 23:58
yes basically when i run the test

waquino
2020-10-07 23:58
is creating the contracts and storing in a folder

matt.fellows
2020-10-07 23:58
how is that ?tagging? it?

waquino
2020-10-08 00:02
i was missing this

matt.fellows
2020-10-08 00:02
yep

abhi.nandan
2020-10-08 06:38
has joined #pact-js

brendan.donegan
2020-10-08 08:18
@matt.fellows that?s ok. I understand now what the issue is anyway. Really appreciate everything you?ve done so far. As I mentioned before, if there?s any way I can jump in and help, I?m cool with that

matt.fellows
2020-10-08 08:25
Thanks, and apologies again

matt.fellows
2020-10-08 08:25
So I think we start up the need as an issue on Pact JS and we can work with you to get it done. Could he a good hacktoberfest item?

brendan.donegan
2020-10-08 08:25
aww, you mean I can?t just update your README with Gr8 Project?

brendan.donegan
2020-10-08 08:26
I can raise an issue. Something like ?url generator needs to support path?s??

matt.fellows
2020-10-08 08:34
@brendan.donegan :point_up: sorry already done here

brendan.donegan
2020-10-08 08:34

brendan.donegan
2020-10-08 08:36
@matt.fellows can I get a rough idea of where to start looking?

uglyog
2020-10-08 08:37
Yeah, that was me

matt.fellows
2020-10-08 09:23
Ron's probably best placed for immediate advice

przemyslaw.dabrowski
2020-10-08 12:36
has joined #pact-js

emiliano.righi
2020-10-08 13:25
has joined #pact-js

yousafn
2020-10-08 17:14
What have I started :joy: going to need a big cup of :tea: before settling down to read this.

yousafn
2020-10-08 17:15
Sounds like you lot are ON IT. kudos, now this is the power of OSS

cariaga.bh
2020-10-08 21:03
has joined #pact-js

matt.fellows
2020-10-08 21:38
Ah yes, this thread got... A little out of hand

campellcl
2020-10-09 00:06
has joined #pact-js

elenitsaa043
2020-10-09 10:00
has joined #pact-js

adriangabrieloros
2020-10-09 11:05
has joined #pact-js

tjones
2020-10-09 12:13
Friends! It's hacktoberfest, and to celebrate, I'm keen to work towards releasing support for V3 specs in Pact-JS. I've created #pact-js-spec-v3 for people to collaborate and discuss implementation. Anyone interested is welcome to join

tjones
2020-10-09 12:22
Also tacos for both @brendan.donegan and @yousafn for the activation energy required to start looking in to this :taco:

brendan.donegan
2020-10-09 12:30
i just had lunch, but thanks :slightly_smiling_face:

ruth
2020-10-09 13:03
This is probably a realy silly question, but I am confused on how to download schema from pactflow to the provider. I?ve been googling it and most articles I found says I need to do it but doesnt give me guidance on how.

antonello
2020-10-09 13:06
HI @ruth, just to clarify, you have a provider written in Javascript and you would need to verify a pact that you have published to pactflow?

ruth
2020-10-09 13:07
So I did the verification part.

ruth
2020-10-09 13:08
The purpose of my question is that if the provider changes there are tests to make sure that it still does what the consumer expects

ruth
2020-10-09 13:08
so I figured I would need to download the schema and then test against that.

ruth
2020-10-09 13:09
but now sure how to download the schema into the provider so I can make those tests.

antonello
2020-10-09 13:10
so it?s the provider verification test that you are talking about. you have written a consumer test and published the pact to pactflow?


antonello
2020-10-09 13:10
(I don?t know what you mean by schema, as there are no schemas in Pact, so I imagine that you meant the pact file between your consumer and provider)


ruth
2020-10-09 13:11
yes the pact file! I believe its a JSON schema.

ruth
2020-10-09 13:12
Yep and I did all those steps


antonello
2020-10-09 13:13
I?m not familiar with that I?m afraid

ruth
2020-10-09 13:13
ah okay, no worries!

phil.endsley
2020-10-09 13:18
In the context of that blog series, Pact is not a schema-based contract test. It is a code-based contract test. That series was talking about other alternatives to do contract testing besides Pact. Ex: For something more provider driven rather than consumer driven


ruth
2020-10-09 13:19
ah okay!

phil.endsley
2020-10-09 13:19
> The purpose of my question is that if the provider changes there are tests to make sure that it still does what the consumer expects If you have pact tests for the consumer and provider, your provider build should inherently do this. Each time the provider builds, it should be downloading the pacts from pactflow and running verifications against it

phil.endsley
2020-10-09 13:20
If you had a breaking change in your provider, such that your services are returning unexpected data, your provider build should fail

ruth
2020-10-09 13:20
got it! So essentially because I verfied it will state if there is any difference between the two and create a diff.

ruth
2020-10-09 13:22
So that means I dont have to create any tests because verifying does it for me. The only tests i need to create is on the consumer side.

phil.endsley
2020-10-09 13:22
When you verify, if the response from the provider doesn't match the expected response defined by the consumer, your test should fail. When that happens, you should get a diff of what was expected vs the actual, similar to other unit tests

ruth
2020-10-09 13:22
That makes sense

antonello
2020-10-09 13:22
no, @ruth - that is incorrect, you need tests both on the consumer and provider side.

antonello
2020-10-09 13:23
if you use the pact broker, the consumer will have some tests that aim at creating the pact and upload it to the broker

antonello
2020-10-09 13:25
the provider will also have tests to ensure that it is indeed compatible with what the consumer expects. if you use the pact broker, the provider tests will have to get the pact from the broker.

antonello
2020-10-09 13:25
The pact is a json file. If you?ve written consumer tests, you will be able to see what?s inside if you?re curious

phil.endsley
2020-10-09 13:25
There's a pact-js workshop that goes through each step of the workflow https://github.com/pact-foundation/pact-workshop-js

ruth
2020-10-09 13:26
thanks Ill check this out now!

cariaga.bh
2020-10-09 14:10
Hi everyone, thanks for this great work. I have a weird issue, im trying add pack consumer tests on one project. Locally works great but on gitlab ci don't works. This is the error: ```ERROR: pact-node@10.10.1/118 on runner-wcLUYPAX-project-2580-concurrent-0: Pact Binary Error: XXX/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir XXX in PATH, mode 040777``` This occurs on docker on Gitlab Runner (docker image: node:14-stretch) The ruby ??standalone need some user or files configuration for work? package.json: `"@pact-foundation/pact": "^9.12.2","jest-pact": "^0.8.1",` Can someone help me? (if need to create a github issue tell me) Thanks a lot :smile:

tjones
2020-10-10 04:28
There's a semantic difference that is worth pointing out: * Consumer pact _tests_ on the consumer side are usually run from a unit testing framework * Provider pact _verification_ on the provider side is a kind of test, but doesn't need to be run from a unit testing framework (I usually don't, but you can if it is easier for you).

matt.fellows
2020-10-10 09:15
I've seen the insecure issue before but I don't think that's the real issue. Could you please share the full log at debug level?

cariaga.bh
2020-10-10 14:42
Thanks for the reply @matt.fellows this is the file. For some reason (that I don't know) when i'm commit the change for get the logs in debug level its works although the warning exists

matt.fellows
2020-10-10 23:16
Thanks

matt.fellows
2020-10-10 23:16
The problem seems to be that it can't assign the port

matt.fellows
2020-10-10 23:16
`Error: Cannot assign requested address - bind(2) for "::1" port 1234`

cariaga.bh
2020-10-10 23:23
Wow! I missed it. I need talk to the devops to know if exists some limitation on for the container on gitlab runner. Thanks a lot!

matt.fellows
2020-10-10 23:57
Of you don't specify a port, pact will find an available one for you and return it in the call to `setup`. Also, you may need to test what host/ip to bind to

matt.fellows
2020-10-10 23:57
E.g. 127.0.0.1

sh.ilgam_pact
2020-10-11 16:13
has joined #pact-js

abubics
2020-10-12 01:03
:taco: for @antonello & @phil.endsley :party_parrot: Always so helpful~*

anastasiia.bielik
2020-10-12 11:13
has joined #pact-js

elenitsaa043
2020-10-12 11:30
Hello all! I have a strange issue appearing when running my pact tests (consumer side). From a quick search I haven?t found any relevant response, but please feel free to forward me to any similar issue? When executing the contracts I get this error warning: ```RROR: pact-node@10.10.1/34891 on **: Pact Binary Error: WARN: No content type found, performing text diff on body``` The tests pass, because the text comparison is verified, but I have added the relevant headers in ```willRespondWith``` headers ```Accept: 'application/json' or 'Content-Type' = 'application/json'``` and it seems to ignore it! Any ideas??

brendan.donegan
2020-10-12 11:57
we have this issue too. would love to know what causes it

matt.fellows
2020-10-12 12:40
Hmm can you please share your code?

matt.fellows
2020-10-12 12:41
(or the pact file actually)

elenitsaa043
2020-10-12 12:58
sure !

elenitsaa043
2020-10-12 12:59
``` it('verify request for generated questionnaire', async () => { await provider.addInteraction({ state: 'send a successful request', uponReceiving: 'A generated questionnaire', withRequest: { method: 'POST', path: `/v1/generate`, headers, body: startRequestBodyShort }, willRespondWith: { status: 200, headers : { Accept: 'application/json' }, body: responseBodyShort } }); await generateScript(startRequestBodyShort.job, 1); return provider.verify(); });```

elenitsaa043
2020-10-12 12:59
I have also tried with ```'Content-Type' = 'application/json'```

elenitsaa043
2020-10-12 12:59
but none of them worked

elenitsaa043
2020-10-12 13:01
I keep taking the same warning error in all cases : ```[2020-10-12T10:42:23.225Z] ERROR: pact-node@10.10.1/34891 on **: Pact Binary Error: WARN: No content type found, performing text diff on body```

matt.fellows
2020-10-12 13:01
What are the request headers?

matt.fellows
2020-10-12 13:02
Accept is definitely the wrong response header though, content-type is what you want

matt.fellows
2020-10-12 13:02
Accept is a request header

elenitsaa043
2020-10-12 13:02
the request headers is just a bearer

elenitsaa043
2020-10-12 13:02
yes, i ve tried with just content-type but it didnt work

matt.fellows
2020-10-12 13:03
Try content type on the request too. It might be warning about that side of the test?

matt.fellows
2020-10-12 13:03
Otherwise I'll take a look with fresh eyes tomorrow morning on the e2e example test in pact JS repo

phil.endsley
2020-10-12 13:03
Quotes around content-type? ```headers : { 'Content-Type': 'application/json' },```

elenitsaa043
2020-10-12 13:04
yeap

elenitsaa043
2020-10-12 13:04
thanks!

aleksmarg
2020-10-12 13:05
has joined #pact-js

deepika.krishnakumar
2020-10-12 15:03
has joined #pact-js

anbansal27
2020-10-12 23:02
has joined #pact-js

olarrmide
2020-10-13 00:49
has joined #pact-js

olarrmide
2020-10-13 00:49
Hi Folks, anyone have experience successfully running pact-node from a windows mapped network drive? I am able to install the npm packages but starting my tests throws this error: _CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows Directory._

matt.fellows
2020-10-13 00:50
why are you running pact-node on a mapped network drive, are you able to elaborate?

olarrmide
2020-10-13 00:53
Corporate Infosec requirements. The ruby executable bundled with the Pact libraries is blocked from running by policy restrictions, when I install directly to my local drive. However, the network location has less restrictions- its whitelisted to allow the ruby.exe run.

olarrmide
2020-10-13 01:02
I?d like to know early enough if it?s possible so I know if I need to find another way. Already invested a whole day into finding a solution.

matt.fellows
2020-10-13 01:02
I?m sorry, I just have no idea here

matt.fellows
2020-10-13 01:03
In theory it should be, but there are limitations on how things can run on network drives (I have previous experience doing this, and it is painful)

matt.fellows
2020-10-13 01:03
Could you please do me a favour, and see if https://github.com/pact-foundation/pact-js#pact-js-v3 solves your issue with permissions?

matt.fellows
2020-10-13 01:03
It?s a new version of Pact

matt.fellows
2020-10-13 01:04
It implements more of the v3 features, but doesn?t fully integrate with all of the Pact Broker features just yet

matt.fellows
2020-10-13 01:04
If you can run it locally, and describe the usage you have, it might be a good option. In the next few months, it should come out of beta

olarrmide
2020-10-13 01:08
Thank you. I?ll check it out.

abubics
2020-10-13 02:14
If the security team is heavy-handed and unmoving, you'll always have trouble :sob: One workaround might be to run dev in docker, as long as they'll allow it. Can unblock a lot of use cases, but has a performance & maintenance cost.

matt.fellows
2020-10-13 02:15
In my experience, places that don?t like you running abritrary binaries usually restrict docker also.

abubics
2020-10-13 02:16
just let me run something sandboxed, how do you expect me to get any work done :upside_down_face:

abubics
2020-10-13 02:17
as I said (unfortunately): > you'll always have trouble :sob:

matt.fellows
2020-10-13 02:18
Last time I worked at a place that locked docker, this is what happened:

matt.fellows
2020-10-13 02:19
We used docker for builds. They couldn?t test the build locally, so just edited the build script directly from bitbucket. There are many pages of scrolling :exploding_head:

matt.fellows
2020-10-13 02:19
anyway, I digress

abubics
2020-10-13 02:55
rip in peace

olarrmide
2020-10-13 03:16
You?re right, Docker isn?t available.

abubics
2020-10-13 04:45
The actual solution is to isolate dev environments properly so you don't have to trust them :innocent: But that's probably a big effort, if no one's started on it yet.

abubics
2020-10-13 04:45
Until then, that policy only slows people down.

abubics
2020-10-13 04:48
(and docker would actually help in that case, because you can throw away the fs layer touched by pact, except for the one JSON file, then everything is secure like you want)

prabhakar.thippa
2020-10-13 04:58
has joined #pact-js

matt.fellows
2020-10-13 05:59
That argument only works with rational people, not irrational policies :stuck_out_tongue:

giadinhluong
2020-10-13 06:24
has joined #pact-js

matt.fellows
2020-10-13 07:49
From what I can see, and glean from a glance at the underlying matching code, is that the _request body_ doesn?t have a content-type associated with it

matt.fellows
2020-10-13 07:50
I can make that error show up if you don?t specify a content-type for the request headers

matt.fellows
2020-10-13 07:51
the response headers are fine in your consumer test - they aren?t being matched by Pact yet (they just get returned as you ask)

matt.fellows
2020-10-13 07:51
Only when you verify the provider does the matching of the _response_ body get done

matt.fellows
2020-10-13 07:51
So at this stage, I?m 90%+ sure that it?s just that you?re missng a content-type on the request body

matt.fellows
2020-10-13 07:53
the `content-type` header is used to signal the content type being sent (in this case, by the consumer). The `accept` header is about what content types the receiver can deal with. The `accept` header makes no sense on the provider - it?s too late, the consumer has already made the request and can?t alter the `content-type`. So you can remove it from the `willRespondWith` block. In your case, _both_ the consumer and provider should specify a `content-type` (and they should both by something like `application/json`)

matt.fellows
2020-10-13 07:53
cc @brendan.donegan - would be ideal to confirm that for you too

matt.fellows
2020-10-13 07:54
After all of that, it?s actually not really a problem either, unless you?re applying matching rules to the _request_ (most times you don?t need to, because you can control what the consumer can send in a unit test - so the warning is just that).

elenitsaa043
2020-10-13 07:57
Ok, thanks a lot for your reply!

elenitsaa043
2020-10-13 07:57
I ll try that!

borsuk.artem034
2020-10-13 08:13
Hello, any progress for this issue? https://github.com/pact-foundation/pact-node/issues/179 maybe somebody find better solution?

pavank
2020-10-13 08:41
has joined #pact-js

matt.fellows
2020-10-13 09:03
Not yet, albeit it is being dealt with in the v4 spec

stephane.meng
2020-10-13 09:06
has joined #pact-js

abirlal.bose
2020-10-13 09:45
has joined #pact-js

alex.elmekeev
2020-10-13 17:24
:wave: do you have somewhere handy an example/guide of migration of existing v2 consumer contracts to v3? I've just noticed that API has changed quite significantly :thinking_face: 1. I'm not sure about `setup` / `finalize` replacement 2. what is the best way to change `addInteraction` to new methods. Right now I'm thinking about some wrappere for PactV3 We have ~400 contracts in v2 and I really don't want to rewrite those :slightly_smiling_face:

uglyog
2020-10-13 22:49
This has been raised as an issue, and something we need to address. Currently, I'm still working on getting it to a non-beta form before we can work on that. However, it has a totally separate name space and contains all the V2 code which can be used along side it, so you can leave your existing tests as is, and only convert some or new ones.

alex.elmekeev
2020-10-14 08:01
can you please share the link to the issue so I can follow it? I've failed to find it in pact-js repo :thinking_face:

mateusz.mrzyglod
2020-10-14 09:32
has joined #pact-js

cathleen.yuan
2020-10-14 11:16
has joined #pact-js

ramana.jaladurgam
2020-10-14 16:10
has joined #pact-js

rodrigocs
2020-10-14 17:55
has joined #pact-js

alik.berezovsky
2020-10-14 18:38
has joined #pact-js

a.robecke
2020-10-14 19:24
has joined #pact-js

mikahchapman
2020-10-14 21:47
has joined #pact-js

uglyog
2020-10-14 22:13
Sorry, I mean someone previously raised it as causing them an issue, not that they created a Github issue for it :smile:

uglyog
2020-10-14 22:13
Please raise a GH issue for it

tjones
2020-10-15 00:28
@alex.elmekeev We haven't finalised the API for V3, I'd like to make sure migration is as smooth as possible. One specific example is that I'd like to still support `addInteraction` with an object (at the moment, migration is easier for people using the current API with the builder pattern, but harder for people using it with an object - which I think is probably the common case)

hem_kec
2020-10-15 00:44
has joined #pact-js

dothetan.040490
2020-10-15 02:22
@dothetan.040490 has left the channel

alex.elmekeev
2020-10-15 08:03
I will hold off with issue creation then if it's anyway a desire to keep "backward compatibility" of API

marco.cordeiro
2020-10-15 10:54
has joined #pact-js

betty.he
2020-10-15 14:32
has joined #pact-js

uglyog
2020-10-16 07:59
:point_up: Array contains matcher! :tada:

alex.elmekeev
2020-10-16 08:11
v3 only, right?

francislainy.campos
2020-10-16 08:11
has joined #pact-js

francislainy.campos
2020-10-16 08:27
Hello, good morning. I'm going through this tutorial https://katacoda.com/mefellows/scenarios/pactflow-getting-started-json on how to write pact with javascript (I know how to do it in java but first time with js) but am getting an error that says `before is undefined` even though I have mocha installed as a dev dependency as per the sample package.json file and also globally. I then tried it with `beforeEach` instead which seems to work a bit better but I then get this error instead saying `PopsicleError: Unable to connect to "http://127.0.0.1:59166/interactions"` Any ideas please?


francislainy.campos
2020-10-16 08:29
Thank you.

matt.fellows
2020-10-16 09:05
Yes

tamer
2020-10-16 09:08
has joined #pact-js

matt.fellows
2020-10-16 10:32
How are you running the pact test?

matt.fellows
2020-10-16 10:32
It looks like a react project, so there is probably Jest in there somewhere

francislainy.campos
2020-10-16 10:33
npm run test consumer

matt.fellows
2020-10-16 10:33
I tried running the `npm run test:consumer` and it doesn?t do anything, because the pact file is not where that command is expecting

francislainy.campos
2020-10-16 10:33
I'm using this `npm run test consumer` without the :

matt.fellows
2020-10-16 10:33
what does that do?

matt.fellows
2020-10-16 10:34
ah

matt.fellows
2020-10-16 10:34
that?s going to run the react tests

matt.fellows
2020-10-16 10:34
that command doesn?t do what you think it does

francislainy.campos
2020-10-16 10:34
No?

francislainy.campos
2020-10-16 10:35
Okay, I'll try your version

matt.fellows
2020-10-16 10:35
no, if you don?t know why, I suggest go and find somebody in your organisation who does and pairing with them for a bit

matt.fellows
2020-10-16 10:36
With respect, it shows that you don?t understand the node ecosystem (which is great that you?re giving it a go!) - but this will be the first of many pain points.

matt.fellows
2020-10-16 10:36
It would be like if I had to deal with Maven :stuck_out_tongue:

francislainy.campos
2020-10-16 10:36
I wear glasses so it may be that I missed the : as am without them at the moment.

francislainy.campos
2020-10-16 10:36
But yeah, it's the first time I'm trying to run tests like this

francislainy.campos
2020-10-16 10:37
But it's a personal project, and don't have a buddy to pair with.

francislainy.campos
2020-10-16 10:37
So trying to figure it out here.

matt.fellows
2020-10-16 10:38
ah ok

matt.fellows
2020-10-16 10:38
`"test:consumer": "mocha --exit --timeout 30000 src/pact/consumer.pact.spec.js",`

matt.fellows
2020-10-16 10:38
that fixes your immediate issue, anyway

matt.fellows
2020-10-16 10:38
the path to the pact file was incorrect

matt.fellows
2020-10-16 10:38
I ran it locally just now

francislainy.campos
2020-10-16 10:38
Thank you. I'll check it here.

matt.fellows
2020-10-16 10:40
here?s the exact patch

francislainy.campos
2020-10-16 10:47
Yeah, it worked. Thanks once again Matt (now in the Javascript word).

francislainy.campos
2020-10-16 10:48
Happy Friday.

mario.gioiosa
2020-10-16 18:57
has joined #pact-js

abubics
2020-10-19 05:17
TESTING BUILD :party_parrot:

lior.baber
2020-10-19 07:33
has joined #pact-js

jeffbdye
2020-10-19 17:10
has joined #pact-js

dmcgill50
2020-10-19 19:16
has joined #pact-js

jace
2020-10-19 19:22
has joined #pact-js

campellcl
2020-10-19 22:46
Hey all, @matt.fellows and @bethskurrie I'm back again on the JS side of things. Running into open issue: https://github.com/pact-foundation/pact-node/issues/100 is the V3 branch for Pact-JS that you mentioned `feat/v3.0.0`?

matt.fellows
2020-10-19 22:47
:wave:

matt.fellows
2020-10-19 22:47
yes that?s correct

campellcl
2020-10-19 22:49
So we need to do a manual build of Pact somehow with the `feat/v3.0.0` branch? We can't pull it down via NPM, right?

matt.fellows
2020-10-19 22:49
no, it?s available by NPM


matt.fellows
2020-10-19 22:49
`npm i @pact-foundation/pact@beta`

matt.fellows
2020-10-19 22:50
Ron was releasing some things yesterday, but pretty sure that tag still works to get the latest in that stream

campellcl
2020-10-19 22:54
Phew. Didn't want to have to build manually and bypass NPM. Great, thanks! I'll try that out.

matt.fellows
2020-10-19 22:55
hahah yes, that would be a pain

campellcl
2020-10-19 22:55
Still getting that problem with the beta version: ```Error: C:/Users/ccamp/Documents/GitHub/MITEPF/JobManagementServiceV3/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.3/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.32.1/lib/pact/provider_verifier/app.rb:3:in `require': cannot load such file -- pact/provider_verifier/provider_states/add_provider_states_header (LoadError)```

campellcl
2020-10-19 22:55
=(

matt.fellows
2020-10-19 22:56
The beta still includes the old DSL, so that means you?re not using the `v3` interface

uglyog
2020-10-19 22:56
I think that issue may be on install?


matt.fellows
2020-10-19 22:56
it?s a new namespace

matt.fellows
2020-10-19 22:56
`const { PactV3, MatchersV3 } = require("@pact-foundation/pact/v3")`

campellcl
2020-10-19 22:57
Ah, missed that. Thank you!

matt.fellows
2020-10-19 22:57
instead of something like `const { PactV3, MatchersV3 } = require("@pact-foundation/pact")`

campellcl
2020-10-19 22:58
Message Pacts in V3?

matt.fellows
2020-10-19 22:58
not yet

matt.fellows
2020-10-19 22:58
I?m currently adding it to Pact Go to see how to do it with the new reference library

matt.fellows
2020-10-19 22:59
I could be wrong, Ron would know.

matt.fellows
2020-10-19 23:00
The windows pathing issue can usually be resolved by moving closer to the root of the volume e.g. rather than `c:\foo\baz\some\deep\nested\folder` move to `c:\pact`

uglyog
2020-10-19 23:01
No JS V3 DSL for messages yet

campellcl
2020-10-19 23:08
Moving what closer to the root of the volume? The test script itself that leverages Pact? This is an internal Pact error. We are trying to pull files from the remote broker. So if anything it would be the internal `node_modules` file paths that are causing the violation.

matt.fellows
2020-10-19 23:09
So the issue is that within the node modules folder of your project dir `C:/Users/ccamp/Documents/GitHub/MITEPF/JobManagementServiceV3/`

matt.fellows
2020-10-19 23:09
there is an internal Pact library that nests within there. The path > 255 characters, which causes that problem

matt.fellows
2020-10-19 23:10
There are 2 known fixes (at least) that I know of: 1. `C:/Users/ccamp/Documents/GitHub/MITEPF/JobManagementServiceV3/` -> `c:/project` (move the project closer to the root of the volume, so the path isn?t as long) 2. The windows registry fixes documented in several pact issues. They could be out of date now with newer versions of Windows, but apparently there is some way to remove this arcane limitation

campellcl
2020-10-19 23:11
Right, I'm just not sure moving that `node_modules` up a few directories will be enough to resolve that, when the internal file paths are so long.

campellcl
2020-10-19 23:11
I've already tried the windows fixes to enable Win32 longer path names

matt.fellows
2020-10-19 23:11
It?s sad this is a problem in 2020

campellcl
2020-10-19 23:11
Agreed haha

matt.fellows
2020-10-19 23:11
yeah

matt.fellows
2020-10-19 23:12
see how you go moving the directory, it?s worth a shot

campellcl
2020-10-19 23:12
Yup, working on it now!

campellcl
2020-10-19 23:33
Yup, that works. Thanks Matt. Now we just need to restructure our folder hierarchy.

tjones
2020-10-19 23:49
^ I think that would be a better solution than moving to the V3 beta, where not all features are complete

matt.fellows
2020-10-19 23:49
well in this case, he needs message pact - so yes, moving to the v3 beta is not going to be super helpful! :stuck_out_tongue:

tjones
2020-10-19 23:50
Is the windows 10 pathing issue something we could do by upgrading the bundled ruby or something?

matt.fellows
2020-10-19 23:51
Can?t update the bundled Ruby, the ?traveling ruby? library we used hasn?t been updated to support modern Ruby?s

matt.fellows
2020-10-19 23:51
I?ll check again now, because it would be great if it did

tjones
2020-10-19 23:53
It looks like it hasn't been updated in a looong time, but maybe there are other projects we could use, eg: https://github.com/pmq20/ruby-packer

matt.fellows
2020-10-19 23:54
I like that idea

matt.fellows
2020-10-19 23:54
On the one hand, it?ll solve some immediate issues

matt.fellows
2020-10-19 23:54
but on the other, I?d much prefer to spend any available time moving to the strategic goals

uglyog
2020-10-19 23:56
traveling ruby is no longer supported, which is most of the problem with the embedded Ruby version

matt.fellows
2020-10-19 23:56
yep. the lib Tim linked to looks gooder (I think we did a scan a few years back)

alik.berezovsky
2020-10-20 09:19
@alik.berezovsky has left the channel

almaak
2020-10-20 09:35
has joined #pact-js

andra.moraru
2020-10-20 14:13
has joined #pact-js

camila.coder91
2020-10-20 17:06
has joined #pact-js

campellcl
2020-10-20 17:20
Will I run into trouble if I publish a consumer pact in Python (not a Message Pact because it isn't supported in Python) and attempt to verify the pact as a Message Pact on the provider side in NodeJS?

campellcl
2020-10-20 17:20
Is there a generic Pact type that will work across both language implementations?

brendan.j.donegan
2020-10-20 19:52
Contracts are language agnostic. We write consumer contracts in JS and verify them with Java

uglyog
2020-10-20 23:23
You will need to transform the stored pact file, because the format is different for messages

julzelements
2020-10-21 05:25
has joined #pact-js

kapil.mathur
2020-10-21 06:40
has joined #pact-js

mark.hudson
2020-10-21 10:45
has joined #pact-js

campellcl
2020-10-21 15:38
@uglyog That is what i was worried about. Is there a type of Pact file that would work without transformation across both implementations. A generic Pact type?

campellcl
2020-10-21 15:38
The problem only stems from mixing Pact message formats right? So as long as the message format type is implemented in both languages, I should be good?

campellcl
2020-10-21 15:44
@brendan.j.donegan Thanks for the response! My question was about the specific implementation of the language agnostic pacts, not the overall philosophy of the language agnosticism in Pact. I understand that the contracts are intended to be language agnostic. I was looking for clarification on if the types of Pacts are intercompatible as well as language agnostic. That answer appears to be: no, they are not. I should have made that distinction a bit more clear in my original question. So although you can write a Pact in JS and verify it in Java, you _cannot_ (it seems; please correct me if I'm wrong) write a *Message Pact* in JS, publish it to a broker, retrieve the message pact and verify that message Pact with a generic *non-Message Pact* (on the provider side) in Java.

cluu
2020-10-21 17:16
has joined #pact-js

tjones
2020-10-21 17:50
Are you asking if you can verify a (say) RabbitMQ message against a provider that exposes an HTTP interface? The answer is no, but any contract verification is certainly a failure anyway if the contract is not met. The ability to specify and verify contracts for messages is not available in all pact frameworks. In your example of JS and Java, it is. With Pact in Python, it is (I believe) not currently supported.

tjones
2020-10-21 17:53
Pact files adhere to the Pact spec. The most widely supported pact specification version is V2. I think message pacts are a V3 feature. In the case of pact-js, message pacts have been cherry-picked into the current released version (which otherwise only supports V2 features). ^ Someone else may correct this, I'm not sure.

camila.campos
2020-10-21 21:35
has joined #pact-js

campellcl
2020-10-21 23:46
> Are you asking if you can verify a (say) RabbitMQ message against a provider that exposes an HTTP interface? Nope, that wasn't what I was asking either. I'm specifically talking about the serverless context, where everything is conceptually a Message Pact. In this paradigm there is no dedicated provider endpoints and no dedicated consumer endpoints. Sometimes microservices provide, and sometimes microservices consume. We need to implement Message Pacts. We have a multi-language environment with some microservices written in NodeJS and some written in Python. The Python version of Pact `pact-python` does not support Message Pacts currently. The NodeJS version of Pact `pact-js` does support Message Pacts. My question was: can a Message Pact written in `pact-js` be validated by `pact-python` even if Pact python does not yet formally support Message Pacts? Does the framework know enough about the Pact specification V3 to still validate the Message pact, even if it can't yet publish them, and has no dedicated namespace (e.g. reserved `MessagePact` class) for them yet? The answer I received from @uglyog in the above thread was exactly what I was looking for. The answer is: no. We will be unable to use Message Pacts, or we will have to write our own Message Pact verifier on the Python side. If `pact-python` supported Message Pacts, then my original question would not be needed.

uglyog
2020-10-21 23:50
There is a way, if you use one of the CLIs to do the verification. I'll check the Rust one to see if it will work, but you would need to create a test endpoint in the Python project that can return the message to be verified.

uglyog
2020-10-21 23:57
The Rust CLI verifier (https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_verifier_cli) can verify a message pact by using a POST request with the message contents to an endpoint. You would just need to create the endpoint on the provider side (which should be easy in Python), that will receive the message (and one for the provider states), and return an appropriate response if it was processed successfully.

uglyog
2020-10-21 23:58
Actually, it's for the message provider, not consumer


campellcl
2020-10-22 00:53
@uglyog Good to know! Thanks! We will consider it! I'm a bit hesitant to try another language. Our foray into `pact-python` did not go well with the example code not even executing on Windows due to how Flask was being used internally. Likewise the `pact-js` example ran into Windows pathing issues from inside the Ruby logic as well, which was not fun to debug. The last thing I want to do is burn yet another full day of dev time on debugging the language-specific implementations of pact on Windows. But it is good to know that an alternative exists!

campellcl
2020-10-22 00:54
At this point we will probably throw together something incredibly hacky to work with the devils we know (e.g. `pact-python` and `pact-js`).

uglyog
2020-10-22 00:56
PRs would always be welcome on the Pact Python repo

matt.fellows
2020-10-22 00:59
If I understand correctly Chris: 1. JS is your message consumer 2. Python is the message provider (producer) You should be able to: 1. Use Pact JS to create the consumer message pact (with the workarounds you?ve established for pathing issues) 2. Use the CLI verifier as per above, to do the message verification on the producer side (i.e. your Python app), adding a simple route that wraps your functions

matt.fellows
2020-10-22 00:59
I think if it was the other way around, the answer would be ?no? at the moment for the reasons you?ve established

campellcl
2020-10-22 01:03
Yup, we would love to contribute. But we don't have the resources to do so. We are a pretty small shop. If we implemented a monkeypatch or something that worked within the confines of the Pact lib the way it was meant to be used, we would not hesitate to contribute it via PR. But most likely we will hack around the restrictions outside of Pact's CLI in a way that is not architecturally sound. I will consider personally contributing on my own time! I've offered to help take up some entry-level Issues on the Python side. But anything beyond that will require a significant time investment on my part, and I'm vested in ML research right now. So not quite my cup of tea haha.

campellcl
2020-10-22 01:13
@matt.fellows Well we are doing serverless. So ideally we would have pacts going both ways. But in the specific example I described above, what you referenced is correct. I will definitely discuss the idea of using the Rust CLI with the team to validate the message pacts. We are already several dev days into Pact with no interoperability between the NodeJS and Python logic to show for it. And it's getting hard to defend that decision. So i'm hesitant to adopt another language implementation. Right now we are entertaining the (normally terrible) idea of interfacing the NodeJS and Python logic via subprocess, translating the python responses into NodeJS Message Pacts and having the Node logic do all the interactions with the broker, including the verification logic. I'm not happy about it, because it's real hacky. But at least I will get to use my local pytest test fixtures, and we can still use pact.

campellcl
2020-10-22 01:16
So if you want that mess of a solution as a PR, I can see about getting permission to push it up. But I'm anticipating that no one will find that solution feasible in the long term.

matt.fellows
2020-10-22 01:20
No you?re spot on with everything you just said :stuck_out_tongue:

campellcl
2020-10-22 01:48
Yeah, figured you wouldn't want that anywhere near the codebase haha. Let me think about the Rust implementation CLI idea some more though. That is very helpful @uglyog, thank you. Would there be any way to publish a Message Pact on the consumer side in Python? Would the Rust CLI support that? I don't see anything about publishing consumer pacts but I might have missed it.

uglyog
2020-10-22 01:50
You can use the normal pact CLI to publish pact files. https://docs.pact.io/implementation_guides/cli/

campellcl
2020-10-22 01:53
@matt.fellows Just said that if the relationship was reversed and Python was the message consumer, and NodeJS was the message provider then that wouldn't work (I thought). Did I misinterpret?

tjones
2020-10-22 02:03
Interacting with the broker can be done by any framework (including the CLI), and is unrelated to your question about defining or verifying message pacts

tjones
2020-10-22 02:06
> Would there be any way to publish a Message Pact on the consumer side in Python? There are two steps. The first is to define (and test) the consumer contract. This produces a pact file. If your consumer testing framework does not support message pacts, it can't be a message pact. That pact file can then be published to a broker. At this point it doesn't matter what "type" of pact it is.

matt.fellows
2020-10-22 02:07
> @matt.fellows Just said that if the relationship was reversed and Python was the message consumer, and NodeJS was the message provider then that wouldn?t work (I thought). Did I misinterpret? As of this moment, that is correct.

tjones
2020-10-22 02:08
Pact doesn't really have types of pacts, it has spec versions. Message pacts are in spec V3, so you need a pact library that can write V3 specs. There's a partial exception to this in that pact-js only supports messages from V3 - the rest of the V3 features are unimplemented or in beta for pact-js.

tjones
2020-10-22 02:10
That is, at the moment pact-js can read and write V3 specs as long as you only use the messages part of the spec, and not the extended matchers or state parameters. Pact python cannot read or write V3 specs. Any pact file of any spec can be published to the broker by any broker client.

tjones
2020-10-22 02:12
From what you've written above, I think you understand the constraints very well, but I think it might be helpful not to think of message pacts as a distinct type of pact.

tjones
2020-10-22 02:13
Perhaps we should add some diagrams to the documentation to help clear this up? What do you think?

uglyog
2020-10-22 02:15
That's not quite true, the message pacts also differ in format, so can not be swapped with HTTP req/res pact files

campellcl
2020-10-22 02:17
Yeah, I'm hearing two different answers here

uglyog
2020-10-22 02:18
Not two different answers, just a clarification on what Tim said.

campellcl
2020-10-22 02:24
I'm a bit confused. So should I not think of message pacts as a distinct type, even though Message Pacts "differ in format"? Because it seems to matter in cross language implementations, when the python broker client doesn't support Message Pacts. The python broker client doesn't seem able to verify a Message Pact published by the NodeJS broker client. To me that implies a pact type system. What am I missing?

campellcl
2020-10-22 02:26
I get what you are saying about the python broker client not supporting V3 spec.

uglyog
2020-10-22 02:26
If you generated a message pact, published it, and then tried to verify it as an HTTP pact, you would get an error from the verifier because the required attributes in the file would not be correct.

tjones
2020-10-22 02:26
> even though Message Pacts "differ in format"? Yes. They are a different version of the pact spec

uglyog
2020-10-22 02:28
Even with V3 pacts, the V3 message pact files have different JSON attributes to the V3 HTTP pact files

campellcl
2020-10-22 02:30
> Even with V3 pacts, the V3 message pact files have different JSON attributes to the V3 HTTP pact files Right. That is what I am saying makes it a different type of Pact in my mind. An HTTP-Type-Pact and a Message-Type-Pact. There is also some confusion when the `pact-js` code has a distinct `MessageProviderPact` and `MessageConsumerPact` class separate from the generic `Pact` class. We assumed that the `Pact` class was the generic HTTP-type-Pact and that the `MessageProviderPact` class represented another distinct other type of pact (a Message-Type-Pact). But you are saying that's a harmful way of looking at it, right @tjones? I will try your approach of not thinking about it like that then.

campellcl
2020-10-22 02:36
> There are two steps. The first is to define (and test) the consumer contract. This produces a pact file. If your consumer testing framework does not support message pacts, it can't be a message pact. But the fact remains, we need Message Pacts up and running in both NodeJS and Python on both sides of the contract. Irrespective of the fact that `pact-python` does not support Message Pacts on the consumer side or the provider side. So what would you recommend then @tjones?

campellcl
2020-10-22 02:36
Use the Rust CLI to perform message pact verification on the provider side in Python via an endpoint running on localhost. I got that part down now thanks to the help I received above.

campellcl
2020-10-22 02:37
I can already use NodeJS to publish message pacts and verify message pacts thanks to `pact-js`.

campellcl
2020-10-22 02:40
So just use the normal Ruby standalone executable CLI to issue message pacts on the Python consumer side via a provider-states endpoint as well?

tjones
2020-10-22 02:55
Yes, you could use the Ruby CLI - and that's what I would personally do. If you're familiar with the node DSL, and don't want to learn anything extra, you could also use the pact-js to do the same thing. For example: https://github.com/pact-foundation/pact-js/blob/master/examples/jest/publish.js

tjones
2020-10-22 02:56
pact-js just wraps the Ruby executable anyway

longlevan
2020-10-22 09:15
has joined #pact-js

justin.garfield
2020-10-22 16:15
has joined #pact-js

campellcl
2020-10-22 16:51
Great, thanks all. You've been a huge help. We will take what you have proposed and run with it and see where we end up. If we come up with a non-hacky solution I'll get a PR open to contribute back to Pact.

guppy0356.nakira
2020-10-23 00:34
has joined #pact-js

ercalbwar
2020-10-24 19:24
has joined #pact-js

andrewshtamburg
2020-10-25 13:04
has joined #pact-js

siad.ardroumli
2020-10-25 18:16
has joined #pact-js

srikanthpmailid
2020-10-26 01:02
has joined #pact-js

photesthesis_geospiza
2020-10-26 15:10
has joined #pact-js

photesthesis_geospiza
2020-10-26 15:13
Hello, everyone! @tjones -- lemme know when you want to jam on https://github.com/pact-foundation/pact-node/pull/238 :smile:

francislainy.campos
2020-10-27 10:11
Hi, good morning. I come from Java and am used to having different files for each consumer contract but them I name them all finishing with the word Test so that once I run a maven command they become part of the same json file and as one single contract. I'm not sure whether this would happen also with Javascript based contracts as I'm on IntelliJ now and I have two mocha files, but when I run one of them the other is overwritten and the contract only shows the last one run.


thomas.hibbard
2020-10-27 14:21
@uglyog `https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/typescript/test/get-dog.spec.ts#L30` You?ve said that anything can be passed to given in the v3 beta, but in the example it still looks like it?s a string.

thomas.hibbard
2020-10-27 14:23
The definition is a little unclear to me ```export declare class PactV3 { /* ... */ given(providerState: string, parameters?: any): PactV3; /* ... */ }``` `given` here looks like a method that return an instance of the `PactV3` class itself. I?m not really sure how this allows for setting up structured data state.

francislainy.campos
2020-10-27 15:55
Thanks @matt.fellows, sorry, only seeing your reply now. I'll try and give it a go and come back here with the results.

thomas.hibbard
2020-10-27 17:10
ah never mind, that was idiotic, I see now it?s just a chainable method. I?m trying to pass it some data to its second argument, and the pact build succeeds, but it keeps giving me an error `Ignoring value for provider state parameter {whatever_key_i_put_in_the_object_in_the_second_parameter}`

francislainy.campos
2020-10-27 19:36
Yes, it worked. Thanks very much. :)

jackbwheatley
2020-10-27 21:02
has joined #pact-js

uglyog
2020-10-27 22:00
Ok, @thomas.hibbard let me fix that

matt.fellows
2020-10-27 22:01
Should it be object that has string keys with any value?

thomas.hibbard
2020-10-27 22:01
Ah Hi @uglyog I can see now that the issue was `given` can take an object, but it seems only one key-value set deep.

thomas.hibbard
2020-10-27 22:02
eg ```{ "itIs": ["nested"], "something": "not nested", "value": "that is a string" } // will result in { "name": "some_given_state", "params": { "itIs": null, "something": "not nested", "value": "that is a string" } }```

uglyog
2020-10-27 22:03
It should support any object that is provided, as long as it can be serialised to JSON

thomas.hibbard
2020-10-27 22:05
This is not the end of the world to be honest. The main problem I am facing is that with the mock server erroring out on `OPTIONS` preflights (even with CORS set to `true`),

carlosalmeida.xon
2020-10-27 22:06
has joined #pact-js

thomas.hibbard
2020-10-27 22:07
or, failing for something like this ```it('should get items', async () => { return provider.executeTest(async (mockserver) => { let response: ILoadItemsResponseBody; try { response = await itemService.loadItems({}).toPromise(); expect(response).toEqual(expectedBody); } catch (specError) { console.error({ specError }); } finally { console.log('test done'); } }); });``` with an error like > Test code failed with an error: Mock server failed with the following mismatches: > > 1) The following request was expected but not received: > Method: GET > Path: /api/items

uglyog
2020-10-27 22:08
if you can provide an example test with the issue, that would help. You can raise a Github issue for it too.

thomas.hibbard
2020-10-27 22:08
I have tried a variety of scenarios including using the `done` callback, return the expectation (this errors because it?s just a boolean evaluation apparently where `executeTest` is expecting a promise I think. I?ve also tried then wrapping it in async/await, etc

thomas.hibbard
2020-10-27 22:09
Yeah I know this is super vague, so I will make an issue on github for sure.

thomas.hibbard
2020-10-27 22:09
I just thought it might be just me using the API incorrectly so I?d check here first.

uglyog
2020-10-27 22:10
That will help. Also, if you compare the examples in https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3 to yours in might help

uglyog
2020-10-27 22:12
I'm going to be working on Pact-JS V3 for the next 2 days, so if we can identify the issues you're having, I can fix them and get a release out

thomas.hibbard
2020-10-27 22:12
yep, this typescript example is what I was working from. Of course nothing is ever simple so I wasn?t able to use just like an axios.get..it has to go through an angular service, so it?s possible I deviated accidentally

thomas.hibbard
2020-10-27 22:14
That?s excellent.

thomas.hibbard
2020-10-27 22:15
I am around and will be working on this tomorrow as well, so feel free to work with me as much as you need.

francislainy.campos
2020-10-28 01:32
Hi, it's me again, sorry. I'm getting this error `UnhandledPromiseRejectionWarning: AssertionError: expected { Object (id, title) } to deeply equal { Object (id, title) }` when I use somethingLike for my object. I can bypass it by skipping my assertion through a try and catch like this ```getMeCategory(urlAndPort).then(response => { try { expect(response.data).to.eql(EXPECTED_BODY) } catch (e) { } done() }, done)``` However, this may not be the ideal solution and I was wondering what is wrong with my code that may be causing this please. It's very similar to the mocha sample. ```"use strict" const {somethingLike} = require('@pact-foundation/pact/dsl/matchers'); const expect = require("chai").expect const path = require("path") const {Pact} = require("@pact-foundation/pact") const {getMeCategory} = require("../api") describe("Category API test", () => { let url = "http://localhost" const port = 8992 const provider = new Pact({ port: port, log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "pacts"), spec: 2, consumer: "FRONTEND", provider: "BACKEND", pactfileWriteMode: "merge", }) const EXPECTED_BODY = { id: somethingLike("58330784-983c-4ae9-a5a1-d8f8d2b70a59"), title: somethingLike("My category") } // Setup the provider before(() => provider.setup()) // Write Pact when all tests done after(() => provider.finalize()) // verify with Pact, and reset expectations afterEach(() => provider.verify()) describe("get /category/58330784-983c-4ae9-a5a1-d8f8d2b70a59", () => { before(done => { const interaction = { state: "a request for a single category", uponReceiving: "a request for a single category", withRequest: { method: "GET", path: "/category/cdb02322-a8a6-4acf-9644-ddf8b24af9e6", headers: { Accept: "application/json", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json", }, body: EXPECTED_BODY, }, } provider.addInteraction(interaction).then(() => { done() }) }) it("returns the correct response", done => { const urlAndPort = { url: url, port: port, } getMeCategory(urlAndPort).then(response => { try { expect(response.data).to.eql(EXPECTED_BODY) } catch (e) { } done() }, done) }) }) })``` Thank you very much.

uglyog
2020-10-28 03:50
I've fixed the provider state issue. This `.given("i have a project", { id: "1001", name: "Home Chores", tags: ["home", "must do"], vals: { id: 100 } })` now generates ```"providerStates": [ { "name": "i have a project", "params": { "id": "1001", "name": "Home Chores", "tags": [ "home", "must do" ], "vals": { "id": 100.0 } } } ],```

brendan.donegan
2020-10-28 09:14
@francislainy.campos this might have something to do with how your getMeCategory function is implemented, can you show that code?

francislainy.campos
2020-10-28 09:15
Sure, ```"use strict" const axios = require("axios") exports.getMeCategory = endpoint => { const url = endpoint.url const port = endpoint.port return axios.request({ method: "GET", baseURL: `${url}:${port}`, url: "/category/cdb02322-a8a6-4acf-9644-ddf8b24af9e6", headers: {Accept: "application/json"}, }) }```

francislainy.campos
2020-10-28 09:15
Thanks

brendan.donegan
2020-10-28 09:49
Seems ok. Might be worth trying to log the response.data and make sure it is what you think it should be

francislainy.campos
2020-10-28 10:23
This is what I get when break point on response.data

francislainy.campos
2020-10-28 10:23
And here the EXPECTED_BODY

brendan.donegan
2020-10-28 10:25
ah yes

brendan.donegan
2020-10-28 10:26
the expected body contains Pact matchers. This is not going to be the same as the response from the mock server

francislainy.campos
2020-10-28 10:26
Yeah, but the funny thing is that it works for my other contracts.

brendan.donegan
2020-10-28 10:26
might depend what kind of comparison you use

francislainy.campos
2020-10-28 10:26
```const EXPECTED_BODY = { category: { id: uuid("58330784-983c-4ae9-a5a1-d8f8d2b70a59"), title: string("My category"), reports: eachLike({ id: uuid("87f2ebeb-880e-4541-bcf1-d317067b9e6b"), title: string("My report"), runDate: integer(1591609820902), //todo: timestamp createdDate: integer(1591609820902) }) } }```

francislainy.campos
2020-10-28 10:27
This one works fine.

francislainy.campos
2020-10-28 10:27
And it's the same piece for comparing them.

brendan.donegan
2020-10-28 10:28
that could be because you are using literal type matchers rather than somethingLike

brendan.donegan
2020-10-28 10:28
you could try changing the other one to use literal types

brendan.donegan
2020-10-28 10:28
so uuid() and string() instead of somethingLike

matt.fellows
2020-10-28 10:46
yep, you?re spot on Brendan

matt.fellows
2020-10-28 10:47
There is a function to strip away all of the matchers and give you the raw payload

matt.fellows
2020-10-28 10:47
But, honestly, don?t do this: `expect(response.data).to.eql(EXPECTED_BODY)`

matt.fellows
2020-10-28 10:48
I?m almost certain you?ve copied from one of our examples, and ?bad matt? (slaps wrist) there are some example assertions that are not very good - and that is one of them

matt.fellows
2020-10-28 10:48
you almost certainly never want to just check that Pact gave you back what you gave it

matt.fellows
2020-10-28 10:49
The mentality for this test is ?I?m writing a unit test of `getMeCategory()` and as a side effect, i?ll also generate a contract for it?

francislainy.campos
2020-10-28 10:51
Thanks you both. Yeah, I copied from the mocha sample. I'm sorry I thought the other file was working but it was actually inside a try and catch that was avoiding that error from happening.

brendan.donegan
2020-10-28 10:52
@matt.fellows that?s what I keep trying to tell people :slightly_smiling_face:

brendan.donegan
2020-10-28 10:52
You can unit test your API functions *with Pact*

brendan.donegan
2020-10-28 10:52
You don?t need to do both, it?s not ?duplication of effort?

matt.fellows
2020-10-28 10:52
I think it should be a rule somewhere, I?ll add it to the docs now

francislainy.campos
2020-10-28 10:53
I think I'll use expect(response.status).to.eql(200) instead

brendan.donegan
2020-10-28 10:53
That?s probably worse

francislainy.campos
2020-10-28 10:54
It's only asserting a 200 and generating a contract once this passes, which should happen always unless there's some error on the contract it.

francislainy.campos
2020-10-28 10:54
The verification will be done by the provider so not sure we need much here on the consumer side?

brendan.donegan
2020-10-28 10:54
TBH it doesn?t matter too much in this situation when you?re just practicing

matt.fellows
2020-10-28 10:54
It _is_ also fair to say, that JS does make some of these assertions less good, because in JS land you don?t usually do a whole lot with the response - JSON is already a first class citizen, so converting to DAOs etc. is lesss common

matt.fellows
2020-10-28 11:06
how does that read?

nasir.amin
2020-10-28 11:07
has joined #pact-js

thomas.hibbard
2020-10-28 11:10
That?s excellent.

jimish.shah.-nd
2020-10-28 11:26
has joined #pact-js

jimish.shah.-nd
2020-10-28 11:29
Hi, I dont seem to find a way to find a matcher for empty array or an array with values. eg [?Monday?, ?Tuesday?] or [] Please help

antonello
2020-10-28 11:30
Hi Jimish, You won?t find it because it?s not supported. You can read more about why here: https://docs.pact.io/faq/#why-is-there-no-support-for-specifying-optional-attributes If both matter, you?d have to implement them separately.

jimish.shah.-nd
2020-10-28 11:37
Thank you @antonello, makes sense :blush:

brendan.donegan
2020-10-28 11:49
The only thing I?d be concerned about is some peoples interpretation of a ?good unit test? :smile:

brendan.donegan
2020-10-28 11:50
Think about it like this, if you?re verifying that contract and it returns an empty array how can you tell if it is because it was supposed to or if it?s because of a bug?

matt.fellows
2020-10-28 11:58
:grimacing:

adam_figgins
2020-10-28 14:20
has joined #pact-js

thomas.hibbard
2020-10-28 15:01
@uglyog `https://github.com/pact-foundation/pact-js/issues/520` Thanks for having a look. I?m around today for any clarification that may help you.

aperdomobo
2020-10-28 15:42
has joined #pact-js

diazguerra2
2020-10-28 16:06
has joined #pact-js

xsamore
2020-10-28 19:52
has joined #pact-js

simon
2020-10-28 20:49
has joined #pact-js

ruben.cagnie
2020-10-29 01:24
has joined #pact-js

abubics
2020-10-29 02:32
Apart from that bit of subjectivity, I think it reads & scans well :ok_hand:

abubics
2020-10-29 02:32
And :taco: for @brendan.donegan, what a helper \o/

272939217
2020-10-29 05:33
has joined #pact-js

matt.fellows
2020-10-29 06:49
@tjones lol just rediscovered a very crude attempt at a Mocha interface I made 4-5 years ago: https://github.com/pact-foundation/pact-js-mocha. It had some of the intentions behind `jest-pact` . I had a vague memory of _wanting_ to do it, but didn?t realise I did :stuck_out_tongue:

tjones
2020-10-29 06:57
Oh cool! Do you think we should clean it up and match the current DSL? (maybe put some semi colons in?)

matt.fellows
2020-10-29 06:58
I was thinking binning it, mostly because there are already too many things to maintain! (and the interface is both tied to a super old mocha and not very useful)

matt.fellows
2020-10-29 06:58
re-writing it would be faster

matt.fellows
2020-10-29 06:58
also no semis

matt.fellows
2020-10-29 06:58
_smacks Tim?s wrist_

tjones
2020-10-29 07:00
(what do you mean? You don't have to rewrite to put semicolons in :smile: )

tjones
2020-10-29 07:00
But yeah, cool. I was wondering how many people are using non-jest test frameworks

tjones
2020-10-29 07:01
it would be cool if we were a bit nicer boiler plate wise.

tjones
2020-10-29 07:01
Do you still use mocha? I have pretty much exclusively switched to Jest

matt.fellows
2020-10-29 07:02
I do, but mostly out of inertia

matt.fellows
2020-10-29 07:02
Jest is probably now the #1 so it makes sense to havve good support for it

tjones
2020-10-29 07:03
I just checked the mocha source. For consistency, I think our mocha interface should follow their convention of using semicolons

tjones
2020-10-29 07:03
:smiling_imp:

matt.fellows
2020-10-29 07:03
:laughing:

matt.fellows
2020-10-29 07:03
Jest get?s ~ 2x the amount of weekly downloads

tjones
2020-10-29 07:04
it *also* has semicolons

tjones
2020-10-29 07:05
Anyway, I would like to do a modern mocha wrapper

tjones
2020-10-29 07:05
I think it'd be helpful

tjones
2020-10-29 07:05
also, with Rust, I reckon we could get better integration with the errors

matt.fellows
2020-10-29 07:05
we _need_ better integration, at the very least

tjones
2020-10-29 07:05
wouldn't it be awesome if failed tests didn't need you to go look in the logs!

matt.fellows
2020-10-29 07:05
yes

tjones
2020-10-29 07:06
I would be prepared to commit at least one less semicolon in exchange for that

tjones
2020-10-29 07:06
:wink:

matt.fellows
2020-10-29 07:06
there are a host of things we need to do to make it feel native - SSL, logginsg etc. all come at a cost because it?s not within the OS


matt.fellows
2020-10-29 07:06
Rust unfortunately has semicolons. But at least they?re semantic

tjones
2020-10-29 07:07
I knew there was something I liked about Rust

driloni92
2020-10-29 09:05
has joined #pact-js

pauloavra
2020-10-29 12:33
has joined #pact-js

uladzislau_danilchyk
2020-10-29 13:15
has joined #pact-js

uladzislau_danilchyk
2020-10-29 13:22
Hi everyone! I have a question regarding creating pact tests for React app which uses GraphQL and Next.JS. I have functional component for rendering product details, e.g. `const productDetails: NextPage<IProps> = () => { ... }` Inside that component I'm using the following query: ``` const { data, error } = useQuery<ProductDetailsQuery>(productDetailsQuery, { variables: {...} });``` But this code is placed in middle of the functional component and I don't understand how to cover such example with test. Could you help me please?

abubics
2020-10-30 01:58
We generally recommend separating the UI from data requests (e.g. network calls). This helps you avoid loading React in your tests, and can also help centralise your API clients, which is useful for grouping interactions by contract .

abubics
2020-10-30 01:59
(Unless I'm misunderstanding your question/problem :innocent: it's very possible)

francislainy.campos
2020-10-30 04:18
Hi @matt.fellows, good morning. Would you know the counterpart for this answer here but on Javascript please? Looking for an equivalent to ```.pathFromProviderState("/meeting/${id}", "/meeting/500")``` https://stackoverflow.com/a/63956890/6654475 Thanks very much.

matt.fellows
2020-10-30 04:19
It currently doesn?t exist I?m afraid

matt.fellows
2020-10-30 04:19
Only JVM supports that magic. We need to update the roadmap on the JS GH repo to get some visibility on this for a roadmap


uladzislau_danilchyk
2020-10-30 07:45
@abubics, thanks for your answer! We just move this logic into separate hooks:)

francislainy.campos
2020-10-30 09:11
Thanks Matt. And would we have any sample for how to write the provider verification using Javascript? I could only find something like somewhere but it gives me a timeout. ```const { Verifier } = require('@pact-foundation/pact'); describe('Pact Verification', async () => { await test('a request for all categories', () => { const opts = { provider: 'BACKEND', providerBaseUrl: 'http://localhost:8081', pactBrokerUrl: 'https://user.pactflow.io', pactBrokerToken: 'mytoken', publishVerificationResult: true, providerVersion: '1.0.0', logLevel: 'INFO', }; return new Verifier(opts).verifyProvider(); }); });```

matt.fellows
2020-10-30 10:23
There are a few examples in the Pact JS repo as well as the CI/cd workshop

matt.fellows
2020-10-30 10:23
Howtolearn

2020-10-30 10:23
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2020-10-30 10:23
See :point_up:

matt.fellows
2020-10-30 10:24
There's also https://docs.pactflow.io/docs/tutorials/ which you can do in a browser in 5 mins... There's lots :joy:

francislainy.campos
2020-10-30 10:26
Thanks. Yes, I think I got this example from the video tutorial, but can try and check it again to see what I may have missed.

matt.fellows
2020-10-30 10:29
Start with the tutorial on Pactflow because it's the simplest. There are working examples in the JS repo/docs as well as two full working workshops - I'm confident one of those will be useful :+1:

francislainy.campos
2020-10-30 12:34
It seems it only times out when trying to connect to the pactflow broker. If I use the below piece to verify the contract locally it works fine. ```const {Verifier} = require('@pact-foundation/pact'); const path = require('path'); describe("Pact Verification", () => { test("a request for all categories", () => { const opts = { provider: 'BACKEND', providerBaseUrl: 'http://localhost:8081', // pactBrokerUrl: 'https://myuser.pactflow.io', // pactBrokerToken: 'mytoken', pactUrls: [ path.resolve(__dirname, '../../pacts/frontend-backend.json') ], publishVerificationResult: true, providerVersion: '1.0.0', logLevel: 'INFO', }; return new Verifier(opts).verifyProvider().finally(() => { }); }) });```

jimish.shah.-nd
2020-10-30 14:22
Hi, I get this error when creating consumer pacts using office vpn, it works fine without office vpn ``` TypeError: Cannot read property 'writePact' of undefined 8 | 9 | afterAll(done => { > 10 | global.provider.finalize().then(() => done()); | ^ 11 | }); 12 | at Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.<anonymous> (pactTestWrapper.js:10:19)``` what is it doing ? Please help !!!

jikogay728
2020-10-30 17:20
has joined #pact-js

matt.fellows
2020-10-30 21:06
Maybe look at increasing the test timeout?

francislainy.campos
2020-10-30 21:29
Yeah, I tried out but it didn't work. Well, it's okay, as I'm using this to test only my local file before anyways, but just so you guys know as it could perhaps be something other people may be getting too, not sure. Thanks.

matt.fellows
2020-10-30 21:30
What does it say with log level set to debug?

matt.fellows
2020-10-30 21:31
I run these demos several times a week, so I'm very confident they work

francislainy.campos
2020-10-30 21:31
Let me try here.

matt.fellows
2020-10-30 21:33
Which example did you copy from? That's a jest error

francislainy.campos
2020-10-30 21:34
Let me find it again.

matt.fellows
2020-10-30 21:34
(Sorry, I just deleted as your token was in it)

matt.fellows
2020-10-30 21:34
I think it may just be jest timing out before it can start all of the pact processes

matt.fellows
2020-10-30 21:35
(I deleted it again, you'll need to retract your output so your creds aren't in it)

francislainy.campos
2020-10-30 21:35
No worries, I'll do that if you still need it.

matt.fellows
2020-10-30 21:36
All good I think I saw what I needed :joy:


francislainy.campos
2020-10-30 21:38
I think this is where I got it from

francislainy.campos
2020-10-30 21:39
I tried to find an example for this verification with mocha as this is how I'm doing the writing of the contracts but couldn't find it so not sure if it would happen there too.

matt.fellows
2020-10-30 21:39
Try updating the timeout as per the workshop: E.g. `"test:pact": "CI=true react-scripts test --testTimeout=30000 pact.spec.js"`

francislainy.campos
2020-10-30 21:41
```const {Verifier} = require('@pact-foundation/pact'); const path = require('path'); // Setup provider server to verify const app = require('express')(); const server = app.listen("8082"); describe("Pact Verification", () => { test("a request for all categories", () => { const opts = { provider: 'BACKEND', providerBaseUrl: 'http://localhost:8081', pactBrokerUrl: 'https://user.pactflow.io', pactBrokerToken: 'mytoken', // pactUrls: [ // path.resolve(__dirname, '../../pacts/frontend-backend.json') // ], publishVerificationResult: true, providerVersion: '1.0.0', logLevel: 'INFO', }; return new Verifier(opts).verifyProvider().finally(() => { server.close(); }, 30000); }) });```

francislainy.campos
2020-10-30 21:42
I tried like this before as am running through IntelliJ and not a npm command.

francislainy.campos
2020-10-30 21:43
I can send you my credentials privately so that you can run this snippet if that would help you a bit more?

matt.fellows
2020-10-30 21:53
I'm just on the go I'm afraid but can look later


matt.fellows
2020-10-30 21:54
Have you tried the above?

matt.fellows
2020-10-30 21:55
It runs in the browser so all you need is your token and Pactflow URL

francislainy.campos
2020-10-30 21:56
No worries. I can verify this same contract fine with the JVM version and the flow credentials. Only thing is that it always shows as never verified and not sure if by any means related to this issue I'm getting here with the JS version.

francislainy.campos
2020-10-30 21:56
I can look at this link too and see.

matt.fellows
2020-10-30 21:57
You'd need to enable publishing of verification results

matt.fellows
2020-10-30 21:57
In Java that's a system property

matt.fellows
2020-10-30 21:57
In JS it's a verifier flag

francislainy.campos
2020-10-30 21:57
Ah cool, thanks.

matt.fellows
2020-10-30 22:25
What's does setting loglevel to debug say?

matt.fellows
2020-10-30 22:25
It may be timing out

matt.fellows
2020-10-30 22:26
But it sounds like a networking issue

matt.fellows
2020-10-30 22:29
Anyhow, look at the troubleshooting docs in the readme and see where that gets you

matt.fellows
2020-10-30 23:38
https://stackoverflow.com/q/64606629/1008568 :taco: for @francislainy.campos who is contributing via some good q&a

blmlcu
2020-10-31 14:51
has joined #pact-js

jimish.shah.-nd
2020-11-02 09:46
for anyone with same problem in future. I added `jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;` in pactTestWrapper.js and it worked

jamescourtoy
2020-11-02 21:04
has joined #pact-js

telmo.ferreira.costa
2020-11-03 11:32
has joined #pact-js

sergii.kopovskyi
2020-11-03 12:35
has joined #pact-js

silverton.gimenes
2020-11-03 17:58
has joined #pact-js

colber16
2020-11-03 18:34
has joined #pact-js

cvoong
2020-11-03 18:55
has joined #pact-js

uladzislau_danilchyk
2020-11-04 13:26
Hi guys! What is the difference between `ApolloGraphQLInteraction` and `GraphQLInteraction`?

anders
2020-11-09 07:37
has joined #pact-js

anders
2020-11-09 07:54
Hello! Is there any way in `pact-js` to assert that different elements of the same array have different structures? Context: I have a JS frontend querying a GraphQL gateway, and the result of the query includes a list of elements which are subtypes of a GraphQL interface (https://graphql.org/learn/schema/#interfaces). I.e. all elements have some common traits (say `foo`), whose presence I can assert easily with a normal `like` call, but the elements also have some fields which are _not_ shared by _all_ elements (call them `bar` and `baz`). You would have the same situation if working with GraphQL unions (https://graphql.org/learn/schema/#union-types), except there would be no common `foo` field. Is there any way I can assert that all elements have a field `foo`, some have a field `bar` and some have a field `baz`?

tjones
2020-11-09 07:57
Yes, although there's an intentional design subtlety here:

tjones
2020-11-09 07:57
For simplicity, lets say that you have three types `A`, `B` and `C` that all could be in the array

tjones
2020-11-09 07:58
if you were able to say something like `eachLike<A | B | C>(someExample)`, meaning "an array of things that could be `A` or `B` or `C`", then you can run in to coverage problems

tjones
2020-11-09 07:59
say your provider can never produce `C`- a test that looks for `A` or `B` or `C` will not pick this up

tjones
2020-11-09 08:00
it's better to use provider states to be more explicit, and have an array that has all of them: ```[ exampleA, exampleB, exampleC ]```

tjones
2020-11-09 08:01
this has some disadvantages if you are unable to specify the order on the provider side

tjones
2020-11-09 08:02
We'd like to support this use case better in the future (eg "examples like each of these" and "examples like each of these in any order").

tjones
2020-11-09 08:03
however, we intentionally don't have an or operator, for the same reason that we don't let `eachLike` have a minimum size of zero (because a provider that always returns an empty array would pass).

anders
2020-11-09 08:07
All right, so your suggested approach is for the provider to return a static array containing an example of each of the types in a known order, and for the consumer to then apply different assertions for the individual elements of that array? I.e. something on the consumer-side like ```{ list: [ like({ foo: "foo", bar: "bar" }), like({ foo: "foo", baz: "baz" }) ] }```

tjones
2020-11-09 08:09
Yes, that's right. You can use provider states to return a few of these situations, depending on what kind of coverage is appropriate (eg, perhaps the array is either `A | B` or `A | C`, but not both).

anders
2020-11-09 08:11
Yeah, makes sense. All right, thanks for your help! :slightly_smiling_face:

tjones
2020-11-09 08:12
You're welcome. This is a frequent question, so please let us know if there's anything you find particularly difficult to cover, or things you would like to be able to express more easily.

anders
2020-11-09 08:15
Will do. :slightly_smiling_face: I reckon it should be fairly straightforward, it just didn?t occur to me that I could make different assertions on individual array elements, when we?ve used `eachLike` for all arrays so far, and I saw no other array-matcher in the pact DSL.

tjones
2020-11-09 08:19
Ah, yes. I've been meaning to add this case to the matchers documentation, this is a good reminder

uladzislau_danilchyk
2020-11-09 08:30
Hi everyone and @matt.fellows I have a question regarding https://pact.canny.io/feature-requests/p/support-reacts-hooks What other ways you are talking about?

tjones
2020-11-09 09:37
Usually, a hook looks something like this: ``` useEffect(() => { let componentMounted = true; if (isLoading) { if (componentMounted) { setIsLoading(true); } api() .getSomething() .then((results) => { setState(results); }) .finally(() => { if (componentMounted) { setIsLoading(false); } }); } return () => { componentMounted = false; }; }, [isLoading]);```

tjones
2020-11-09 09:37
the pact test can invoke ``` api() .getSomething()```

tjones
2020-11-09 09:37
in the component test, you can then mock out the `api` layer

tjones
2020-11-09 09:39
https://github.com/TimothyJones/react-api-layer-example/commit/fa12e491604fa997b35576e24d55b588af4da6dc ^ See this commit for an example modifying the hook in the React docs to have an API layer.

tjones
2020-11-09 09:42
React best practices are a bit out of scope for this channel, but in general, I don't think it's good practice to have API fetch code directly in the hook. I suspect the reason the example in the react code has the fetch directly in the hook is just so all the context is there (and API layering is out of scope for the example).

matt.fellows
2020-11-09 10:57
:point_up:

matt.fellows
2020-11-09 10:57
We really need that recipes page for good answers like this!

matt.fellows
2020-11-09 11:01
Tim (and possibly @anders ), for future consideration. Ron has just been adding an ?array contains? matcher to the core engine and JS, which doesn?t address exactly what your needs are, but thought I?d let you know. You can see an example of this here: https://github.com/pactflow/example-siren/blob/master/consumer/src/__tests__/delete-order.spec.js#L73-L84

matt.fellows
2020-11-09 11:02
Blog post coming out soon, but ```The new matcher works by providing a list of required items (which can be totally different objects), and it will match the actual list from the provider if all the required variants match at least one item in the list.```

matt.fellows
2020-11-09 11:02
So this might be useful to you, if that holds. The problem Tim was referring to earlier, is that if you get one or the other object, we can?t be sure your code can handle it unless both are returned. This new matcher satisfies that issue

anders
2020-11-09 12:52
Ah, cool, thanks for the heads up!

pbobba
2020-11-09 23:03
has joined #pact-js

jun.li
2020-11-09 23:05
has joined #pact-js

douweicai
2020-11-10 04:11
has joined #pact-js

christian.huber
2020-11-10 09:20
has joined #pact-js

vuttithatkrongyot
2020-11-10 10:57
has joined #pact-js

dan.iosif
2020-11-10 17:06
has joined #pact-js

denitsa.kulezich
2020-11-11 09:19
has joined #pact-js

uladzislau_danilchyk
2020-11-11 11:46
I have an expected response code like this: ```willRespondWith({ .... body: { data: { a: Pact.Matchers.string('My string') b: 'my another string' } } });``` Why does the Pact do not validate my `b` response attribute by value? It validates attribute by type only..

brendan.donegan
2020-11-11 12:52
do you have an example of the failing verification output?

uladzislau_danilchyk
2020-11-11 12:53
After running on provider side it doesn't fail

brendan.donegan
2020-11-11 12:54
so data.b is not ?my another string? and you?re sure of that?

uladzislau_danilchyk
2020-11-11 13:48
@brendan.donegan, Pact adds to pact file matcher by type even if I don't use Matcher for data.b at all

abubics
2020-11-11 21:48
Seems weird, you're right. Do you have a fuller example? This sample code is missing a comma, so I guess it's not quite copied directly from your actual test.

rodrigo.costa20
2020-11-12 00:59
has joined #pact-js

yong.gong188
2020-11-12 09:13
has joined #pact-js

anandhadeepak
2020-11-12 13:03
has joined #pact-js

uladzislau_danilchyk
2020-11-12 13:05
@abubics, ``` beforeEach((done) => { globalAny.provider .addInteraction( new Pact.ApolloGraphQLInteraction() .given('authenticated EndUser') .uponReceiving('a UserQuery') .withRequest({ path: '/graphql', method: 'POST', }) .withOperation('UserQuery') .withQuery( ` query UserQuery { currentUser { email cart { valid __typename } __typename } }` ) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json;charset=UTF-8', }, body: { data: { currentUser: { email: Pact.Matchers.email(''), cart: { valid: Pact.Matchers.boolean(true), __typename: 'Cart', // here matches by type instead }, __typename: 'EndUser', // the same }, }, }, }) ) .then(() => done()); });```

uladzislau_danilchyk
2020-11-12 13:07
Hi everyone! I didn't found docs how I can use versioning in PactJS. How can I set version for consumer with PactJS?

abubics
2020-11-12 13:09
I would've expected that to work, but I haven't used pact-js in a while. https://github.com/pact-foundation/pact-js#matching seem to suggest a specific string value matcher now ```const { string } = Matchers // ... body: { ... name: string("Billy"), ...```

uladzislau_danilchyk
2020-11-12 13:10
@abubics I have used string matcher before but it matches only by type. If I'm not using this matcher I have the code above, it works the same (matching by type)

brendan.donegan
2020-11-12 13:12
you pass the --consumer-app-version flag to the pact-broker publish command

abubics
2020-11-12 13:14
Oh right, the table says "will match a string value", rather than "match any string". It'd be nice to make the docs more explicit, because it scans as more specific than it means.

abubics
2020-11-12 13:14
As I said, your code looks right, you might want to raise a defect.

abubics
2020-11-12 13:16
There's a (very minor?) chance the Apollo DSL is out of sync with regular pact-js matchers, too, I guess? I'd be surprised, but it might be a clue.

uladzislau_danilchyk
2020-11-12 13:16
@abubics, i will raise a ticket in github repo and team will check)

david.dias
2020-11-12 20:04
has joined #pact-js

matt.fellows
2020-11-12 20:44
What does the generated pact file look like?

matt.fellows
2020-11-12 20:44
From casting my eyes over that it should match on exact value indeed

matt.fellows
2020-11-12 20:45
If you can share the verification log file that shows the req/res that pact sees that will also help

uladzislau_danilchyk
2020-11-13 09:19
@matt.fellows, the generated pact file looks the same as using `Pact.Matchers.string()`

uladzislau_danilchyk
2020-11-13 09:20
@matt.fellows, I will try to share

matt.fellows
2020-11-13 09:39
We?ll need a reproducible example, so if you can fill out an issue at: https://github.com/pact-foundation/pact-js/issues/new we can look at it

billal.patel
2020-11-13 10:31
has joined #pact-js

louis.oliver
2020-11-16 10:33
has joined #pact-js

ashishkujoy
2020-11-16 15:08
has joined #pact-js

pradeepchoube
2020-11-17 03:49
has joined #pact-js

brendan.donegan
2020-11-17 10:50
Thanks @matt.fellows and @uglyog :smile:

brendan.donegan
2020-11-17 10:50
I?ll be getting us updated and let you know if there are any issues

matt.fellows
2020-11-17 11:20
You can thank Ron for that!

brendan.donegan
2020-11-17 12:22
QQ - I?m going to need to write any new tests that need to use this feature using Pact V3, is it okay to ?merge? v2 and v3 contracts or would I have to convert any existing tests for the same consumer/provider pair to v3 as well?

meng-lingtao
2020-11-17 14:39
has joined #pact-js

pabvidcal
2020-11-17 15:30
has joined #pact-js

pabvidcal
2020-11-17 16:05
Hi! First of all congratulations for this great framework :slightly_smiling_face: I wanted to ask you a question about pact response I have a case in which in the backend I add a new header to the request, so the frontend instead of a GET request makes a HEAD request. Is there any way to get the headers of an interaction using pact?

pabvidcal
2020-11-17 17:34
I don't know if it can be caused because the pact server is not setting the Access-Control-Allow-Header to true anyhow :thinking_face:

uglyog
2020-11-17 21:53
It currently won't merge them, but I'm thinking for changing that by letting it upgrade older spec pacts to the newer version.

uglyog
2020-11-17 21:53
Something for the next release.

abubics
2020-11-17 23:05
I assume you can just write a test that makes a HEAD request. Are you having trouble because the browser makes a HEAD request that you're not in control of?

abubics
2020-11-17 23:06
I usually leave browser-specific things out of Pact, because it's not really part of the interaction. I don't run the Pact tests from a browser, either, so it doesn't get in the way.

abubics
2020-11-17 23:07
Although, you probably do want some automated test coverage around CORS. I would tend to pick another kind of testing to ensure that :slightly_smiling_face:

matt.fellows
2020-11-17 23:36
what @abubics says :taco:

tjones
2020-11-18 00:02
@pabvidcal Have you enabled cors in the pact options?

matt.fellows
2020-11-18 00:28
what does the expected request/response details look like @pabvidcal

magesh.nagamani
2020-11-18 05:15
has joined #pact-js

pabvidcal
2020-11-18 07:05
Thanks for the help guys my interaction would be this one: ``` { state: 'stateless', uponReceiving: 'description', withRequest: { path: 'my path', method: 'HEAD', headers: { Authorization: 'VALID_TOKEN' } }, willRespondWith: { status: 204, headers: { 'X-Resource-Count': '3' } } };``` From a specific service I make *head* request only to retrieve this custom resource. The functionality works fine but when I run the test I don't receive any custom resource from this response. @tjones yes, I have cors activated in the pact options

tjones
2020-11-18 07:35
What error are you getting?

matt.fellows
2020-11-18 07:37
Is the error on the consumer or provider side of the test?

pabvidcal
2020-11-18 07:38
Hi! I don't get any error. I just don't receive the custom header with the response. The problem is on the consumer side

matt.fellows
2020-11-18 07:53
If you could please provide a minimal reproducible example and submit a bug report that would really help

brendan.donegan
2020-11-18 08:23
So in the meantime all tests that use the same provider need to be V3?

brendan.donegan
2020-11-18 08:24
This is only really a big deal because afaik jest-pact doesn?t support v3

brendan.donegan
2020-11-18 08:25
When it does I will just convert everything to v3 anyway

jstoebel
2020-11-18 13:53
has joined #pact-js

uglyog
2020-11-19 04:16
Actually, I started to implement this, and after writing a test, looks like it does upgrade the existing pact

uglyog
2020-11-19 04:17
It won't work if another V2 test runs afterwards, though

daniel.sayer89
2020-11-19 10:33
has joined #pact-js

art.ptushkin
2020-11-19 10:34
has joined #pact-js

pact457
2020-11-19 10:36
has joined #pact-js

ajerthan.sivayoganath
2020-11-19 10:38
has joined #pact-js

philipchardwick
2020-11-19 11:05
has joined #pact-js

tanzmann
2020-11-19 11:09
has joined #pact-js

olivier.quere
2020-11-19 12:10
has joined #pact-js

wilfried.vandenberghe
2020-11-19 12:19
has joined #pact-js

alan.hanafy
2020-11-19 19:28
has joined #pact-js

michael.deutscher
2020-11-19 21:39
has joined #pact-js

gerry.power
2020-11-20 03:31
has joined #pact-js

alex900
2020-11-20 05:08
has joined #pact-js

tomas.panik
2020-11-20 08:28
has joined #pact-js

marc.ferland
2020-11-20 14:43
has joined #pact-js

sebastien.crapoulet
2020-11-20 15:24
has joined #pact-js

adutrillaux
2020-11-20 15:28
has joined #pact-js

sebastien.crapoulet
2020-11-20 15:31
I'm hoping someone can help me, please do note I have little experience with Pact. I'm investigating integrating Pact tests with our E2E tests using Cypress. Obviously found https://pactflow.io/blog/cypress-pact-front-end-testing-with-confidence/. I know this is still a WIP plugin however I had a question that I would need clearing up: I would obviously like to setup some consumer/provider tests between our FE and our endpoints. My problem is, we need to run these E2E tests in a 'live' environment as we have no staging, and cannot test the features we would be testing when we want. The idea is, to use that plugin (when ready) to generate a mocked BE for cypress, avoiding triggering unwanted things in production. My question is: When a consumer provides a contract to the broker, does the broker consistently run the provider test, or does it simply used something cached on the broker which is given when the provider triggers a build? I hope this makes sense, trying to wrap my head around everything :slightly_smiling_face: Thanks!

he
2020-11-20 15:59
has joined #pact-js

ivgeni.slabkovski
2020-11-20 21:52
has joined #pact-js

matt.fellows
2020-11-20 23:48
Hi @sebastien.crapoulet! so first up, even if you use Cypress, you could still use Pact in your unit testing framework to get the benefits described in that post. This way, you don?t need a live environment at all.

matt.fellows
2020-11-20 23:49
Assuming there are (good) reasons to run Pact as part of your Cypress tests, you could borrow the code from the sample repository there as a starting point (in fact, we?ve been using Pact+Cypress at Pactflow for a few months now based on that post, so we should update the example with our recent learnings)

matt.fellows
2020-11-20 23:50
> My question is: When a consumer provides a contract to the broker, does the broker consistently run the provider test, or does it simply used something cached on the broker which is given when the provider triggers a build? The broker simply maintains the contract, versions it and stores information about the consumers that need it, and the providers that maintain it

matt.fellows
2020-11-20 23:50
So the broker never runs the test. The provider builds will fetch the contracts from the broker and run the pact tests in their CI pipeline

matt.fellows
2020-11-20 23:50
howtonirvana

2020-11-20 23:50
This workshop demonstrates those principles in action: https://docs.pactflow.io/docs/workshops/ci-cd/

matt.fellows
2020-11-20 23:51
:point_up: that workshops takes you through how to implement the effective pact setup guide as aka ?pact nirvana?

matt.fellows
2020-11-20 23:51
howtotutorial


matt.fellows
2020-11-20 23:52
:point_up: have a look at these tutorials firs, because you can do them in the browser and it should give you a better idea of how it all hangs together with the broker

serhatburakyildirim
2020-11-21 21:57
has joined #pact-js

przemyslaw.dabrowski
2020-11-22 11:46
Hello everyone, i am new to the pact. Right now i struggle with matching complex objects. I could not find any information how to match field with inherited types. Can you point me in the right direction ? My backend request body matcher looks like this: ``` export interface Cost { type: string; } export interface CppCost extends Cost { cpp: number; } export interface CpmCost extends Cost { someField: number; someField2: number; } export interface BackendRequest { a: number b: { a: string; b: Cost }[]; } const BACKEND_MATCHER = { c: string('a'), b: eachLike( {a: 'test', b: {cpp: 1, type: 'asd'}}, // CpmCost ?? {min: 2} ), }``` How do i match both Cost (CpmCost or CppCost) types ? In given example obviously only request with CppCosts works

matt.fellows
2020-11-22 12:37
In the current stable version, You need to write two tests to cover each case.

matt.fellows
2020-11-22 12:37
In our v3 branch, there is a new `arrayContains` matcher that I think could work for you.

przemyslaw.dabrowski
2020-11-22 12:51
Thank you for answer. I will check v3 branch. But in current version with two test cases i still wont cover case where array contains values with cpp and cpm at the same time? Am i correct ? [{b: {...} as CppCost}, {b: {...} as CppCost}]

alnasl
2020-11-22 18:46
has joined #pact-js

matt.fellows
2020-11-22 20:40
That's correct. You would usually use a provider state to ensure that only the values of the specific subtype are present in the response for each cases

abubics
2020-11-23 01:48
As an aside, being able to parse responses that have both types might be better positioned as a unit test.

ashutosh23802
2020-11-23 06:20
has joined #pact-js

przemyslaw.dabrowski
2020-11-23 08:58
One last question regarding v3 beta build - is there any example how use it with PactWeb ?

sebastien.crapoulet
2020-11-23 09:02
@matt.fellows thank you so much for your answer, it's clarified my needs :slightly_smiling_face:

matt.fellows
2020-11-23 10:32
ah, it?s not possible at the moment I?m afraid :disappointed:

matt.fellows
2020-11-23 10:32
Is this because you?re using Angular/Protractor?

matt.fellows
2020-11-23 10:33
If possible, use a server side test framework like Jest/Mocha/etc.

matt.fellows
2020-11-23 10:33
You?re welcome!

leonty
2020-11-23 10:33
has joined #pact-js

przemyslaw.dabrowski
2020-11-23 11:14
Yes, i am using pact with Angular. Again - Thank you very much for help ! :)

dariusz.piwko
2020-11-23 11:34
has joined #pact-js

dariusz.piwko
2020-11-23 11:34
Hi

dariusz.piwko
2020-11-23 11:35
@Matt, according to my last message to you I have a question about pact with graphql

dariusz.piwko
2020-11-23 11:35
```Key: - is expected + is actual Matching keys and values are not shown { "body": { - "query": /\s*query\s*getLineitems\s*\(\$limit:\s*Int,\s*\$offset:\s*Int,\s*\$sort:\s*JSON,\s*\$filter:\s*JSON,\s*\$isDetail:\s*Boolean\s*=\s*true\)\s*\{\s*dream_adserver\s*\{\s*lineitems\s*\}\s*\}/ + "query": "query getLineitems($limit: Int, $offset: Int, $sort: JSON, $filter: JSON, $isDetail: Boolean = true) {\n dream_adserver {\n lineitems {\n total_count\n __typename\n }\n __typename\n }\n}\n" } }```

dariusz.piwko
2020-11-23 11:37
If I make more than one nested query I have a error like above

dariusz.piwko
2020-11-23 11:39
```.withQuery( ` query getLineitems (\$limit: Int, \$offset: Int, \$sort: JSON, \$filter: JSON, \$isDetail: Boolean = true) { dream_adserver { lineitems } }`)``` It makes an error, but ```.withQuery( ` query getLineitems (\$limit: Int, \$offset: Int, \$sort: JSON, \$filter: JSON, \$isDetail: Boolean = true) { dream_adserver }`)``` works

matt.fellows
2020-11-23 12:09
Sorry! :pensive:

billal.patel
2020-11-23 12:46
Hi, I am in need of some help please :slightly_smiling_face: Our negative tests are failing on the verifier side. We have a scenario which consists of a POST request to URL like this: `https://domain.com/api/${empty}/12345` When hitting this same URL with the same headers/body in Postman, it returns the expected `400` however, on Postman, when I deform the URL such as this: `https://domain.com/error-api/${empty}/12345` I get `"message": "Missing Authentication Token"` It seems like the endpoint being passed on from the consumer side is getting malformed when the expected URL should be: `https://domain.com/api//12345` Any ideas or help with this would be really appreciated!

tjones
2020-11-23 12:47
Did you mean to write Pact in one of the places that says Postman?

tjones
2020-11-23 12:47
Are you able to share the relevant code snippedt?

tjones
2020-11-23 12:48
Where do you get "Missing Authentication Token"?

billal.patel
2020-11-23 12:50
Hey Tim! Thanks for getting back to me. Oh no, I did mean Postman. I was trying various forms of the URL to workout how to get the endpoint to `"Missing Authentication Token"` in ?real life? by using Postman

billal.patel
2020-11-23 12:51
Would you like the consumer side or the provider side? :slightly_smiling_face:

tjones
2020-11-23 13:23
Are you experiencing this error on the provider side? Perhaps the consumer test test that generates this expectation, then we can help you make a postman request that does it

tjones
2020-11-23 13:23
so, the missing auth token error is specifically coming from your real provider?

tjones
2020-11-23 13:23
Do you normally need an authentication token for this endpoint?

billal.patel
2020-11-23 13:59
Thanks for the help! So the error happens on the provider side (seems like when the provider side request is actually being made)

billal.patel
2020-11-23 14:00
I am able to see that error in Postman too. It occurs when the endpoint is not correct. So for example `https://my-url.com/endpoint//123` works but `https://my-url.com/invalid-endpoint//123` does not work

billal.patel
2020-11-23 14:01
What we are trying to test is the `//` part above which is basically validating what happens when the value passed through is empty

billal.patel
2020-11-23 14:01
I hope that makes some sense

billal.patel
2020-11-23 15:46
By the way, the URL (https://my-url.com) is set in the provider side in `providerBaseUrl` and the endpoint is set in the consumer side in `path`

billal.patel
2020-11-23 15:47
It seems like when they are combined in the request, something is getting messed up. However, when the provider side tests are run, I have no idea how to print/log the full actual URL that Pact generates

praneeth.kumar
2020-11-23 16:18
has joined #pact-js

jarmy
2020-11-23 23:40
Hi. We have branches (e.g. `task/GRNWEB-2077-fast-follow`) that are supposed to be added when a pact is published ```Publishing pacts to broker at: https://pact-broker.docker.savagebeast.com/ 12:16:50 [2020-11-23T20:16:50.640Z] INFO: pact-node@10.11.0/66205 on jenkins-build-agent-09: 12:16:50 12:16:50 Tagging version 548f6b61 of web as "task/GRNWEB-2077-fast-follow" 12:16:50 Publishing web/pegasus pact to pact broker at https://pact-broker.docker.savagebeast.com/``` However, the pact is uploaded but I'm not seeing that tag (or any like it) in our pact-broker (`2.57.0.0`). Is it possible the pact-broker is omitting tags with "/" in them?

jarmy
2020-11-24 00:26
copied ^ to #pact-broker

matt.fellows
2020-11-24 05:08
sorry, will follow this in #pact-broker Pretty sure it?s supported though!

dariusz.piwko
2020-11-24 09:00
@matt.fellows Could you help with topic above?

dariusz.piwko
2020-11-24 09:01
It seems regex doesn't work good

mark.white
2020-11-24 09:03
has joined #pact-js

tjones
2020-11-24 12:43
We're planning to add some better logging to pact-js's provider verification in the next couple of days (the feature is almost ready to go), but for now are you able to see the actual request in the provider logs?

tjones
2020-11-24 12:44
Also, if you could share the consumer test or the relevant part of the pact file, that would be very helpful

billal.patel
2020-11-24 12:54
Ah nice, better logging would be lovely! I can see the info/debug logging of the test, and the verification results that are published to the Pact Broker.

billal.patel
2020-11-24 13:07
Here is a snippet of the consumer test. Please note on line 17 the // which is what we are testing with the value missing

billal.patel
2020-11-24 13:07
I have been asked to rename the company related info but hopefully that still gives a good illustration of what is happening

tjones
2020-11-24 13:37
We sometimes see mismatches where eg the consumer test includes eg `/api/v1/` but the provider base URL also includes it, so the tests hit `/api/v1/api/v1`

tjones
2020-11-24 13:38
it looks like that's not what is happening here

tjones
2020-11-24 13:39
As an aside, this looks like sometime I wouldn't expect to be tested - usually you would only test the behaviour the consumer is relying on

tjones
2020-11-24 13:39
(but perhaps you do rely on this, I don't know)

tjones
2020-11-24 13:40
Also, the intention of state is to indicate any expected pre-conditions present at the provider, but it looks like you might be describing the request with it

tjones
2020-11-24 13:42
it's still weird though. Is `apiKey` the authentication token that the provider thinks is missing?

tjones
2020-11-24 13:43
I don't see a definition of `REQUEST_BODY` in that code, but I take it that you did match it with the one you tried in postman.

tjones
2020-11-24 13:45
My gut feeling is that the problem lies on the provider side, rather than in pact.

tjones
2020-11-24 13:46
I'll see if I can get some time to merge the extra logging code tomorrow, perhaps that will help.

tjones
2020-11-24 13:54
Hmm.... a google search suggests some Ruby tooling is used to replacing `//` with `/` in URLs (even though this is not correct, the rationale is that it is more likely to be a path traversal attack rather than intended, which.... is probably true). I wonder if the double slashes are not being faithfully reproduced by the Ruby code.

tjones
2020-11-24 13:55
(pact-js is backed by the ruby pact binaries)

tjones
2020-11-24 13:55
I'll do some more digging in the morning

billal.patel
2020-11-24 14:26
Thank you so much for the detailed responses. This is more of a negative test which we would like to cover if possible. The API key is something that the endpoint expects and the provider side adds in the headers

billal.patel
2020-11-24 14:27
That Ruby info you sent seems exactly like what we?re facing because when I hit the endpoint in Postman with just 1 / instead of // it displayed the `"message": "Missing Authentication Token"` error we see in this Pact test

billal.patel
2020-11-24 14:27
I do really appreciate you looking in to this :slightly_smiling_face:

ufuk.ozcelik
2020-11-24 14:58
has joined #pact-js

stefanos.varsanis
2020-11-24 16:48
has joined #pact-js

lalexander2810
2020-11-24 16:53
has joined #pact-js

sivaprasad9
2020-11-24 20:46
has joined #pact-js

matt.fellows
2020-11-25 07:34
hmm, yes it could just be a bad regex trying to glob the space

matt.fellows
2020-11-25 07:34
I believe there is at least one issue on pact-js that matches this - have you had a look to see?

matt.fellows
2020-11-25 07:34
I haven?t had a chance to put together a more complex gql example for a while, so would need to get back into that headspace

matt.fellows
2020-11-25 07:35
ultimately, you could always avoid using the graphql interface in Pact JS and perform your own request matching (with your own crafted regex).

matt.fellows
2020-11-25 07:35
I?d like to fully support it in the Pact DSL, but that would require substantial changes across the ecosystem (still on the cards, but a long term roadmap item)

dariusz.piwko
2020-11-25 09:10
Thanks for the reply. Do you have any example to use own request mathing? What do you mean about that?

matt.fellows
2020-11-25 11:44
Well, a standard Pact tests just needs to be told what request its expecting

matt.fellows
2020-11-25 11:45
``` provider .given("is authenticated") .uponReceiving("a request to create a new mate") .withRequest({ method: "POST", path: "/graphqlendpoint", body: "<put gql query here>", }) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: "<put expected response here>", })```

matt.fellows
2020-11-25 11:47
GraphQL is just an abstraction over HTTP, so if the GraphQL interface isn?t working, you can always fall back to the standard pact test interface to get more specific matching happening

matt.fellows
2020-11-25 11:48
I believe the issue is that the regex the GraphQL interface is trying to apply is not working for all circumstances ```const escapeRegexChars = (s: string) => s.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")``` That?s what is currently used to match the expected query with the actual one

scyr
2020-11-25 14:56
has joined #pact-js

timotheus.ruprecht
2020-11-25 22:12
has joined #pact-js

tjones
2020-11-26 00:42
@billal.patel: I've looked into this a bit, and I can't reproduce it yet. If I set up an interaction with `/foo//bar`, then the provider does get the request correctly, so Ruby isn't the culprit.

tjones
2020-11-26 00:42
Can you confirm that the expected URL is present in your pact file?

tjones
2020-11-26 00:43
It might help if you're able to create a repository that reproduces the problem, then we can take a look

tjones
2020-11-26 00:44
I'll also try to get that improved logging out to you soon (haven't had as much time for Pact dev this week as I would like)

tjones
2020-11-26 01:05
also, which versions of pact and pact-node are you using? You can find out with `npm ls @pact-foundation/pact-node`

abhi.nandan
2020-11-26 07:13
Hi, I am using `pathFromProviderState` in pact-jvm for injecting values from provider state. What is the pact-js equivalent of that? is there any example available?

tjones
2020-11-26 08:11
Hi! This is a pact spec V3 feature, which is currently not available in the stable release. However, you can try the beta v3 release, following the instructions here: https://github.com/pact-foundation/pact-js#pact-js-v3 There's an example of the provider state here:


abhi.nandan
2020-11-26 08:26
thanks @tjones

billal.patel
2020-11-26 09:46
Hey Tim. Thanks for looking in that for me

billal.patel
2020-11-26 09:46
I have checked in the Pact json file and the path does have a `//` in there

billal.patel
2020-11-26 09:47
The version I am using is: @ pact-foundation/pact-node@9.13.0 ??? @ pact_foundation/pact-node@10.11.0

manali.mogre
2020-11-26 11:44
has joined #pact-js

erik.terpstra
2020-11-26 12:08
has joined #pact-js

kjayachandra2000
2020-11-26 20:40
has joined #pact-js

kjayachandra2000
2020-11-26 22:00
@kjayachandra2000 has left the channel

sushil.kumar
2020-11-27 01:45
has joined #pact-js

zhujian
2020-11-27 07:54
has joined #pact-js

h.octavian
2020-11-27 14:08
has joined #pact-js

noel
2020-11-28 23:12
has joined #pact-js

dariusz.piwko
2020-11-29 22:01
It seems your regex is correct ```function validateExample(example, matcher) { // Note we escape the double \\ as these get sent over the wire as JSON console.log('MATCHER', matcher); console.log('EXAMPLE', example); console.log('**************************', new RegExp(matcher.replace("\\\\", "\\")).test(example)); return new RegExp(matcher.replace("\\\\", "\\")).test(example); }``` returns true

dariusz.piwko
2020-11-29 22:02
I have a problem here

dariusz.piwko
2020-11-29 22:15
Do you have any idea how to fix this?

matt.fellows
2020-11-29 23:06
what does the log file say?

muraalee
2020-11-30 01:56
has joined #pact-js

dariusz.piwko
2020-11-30 07:45
I don't understand because as you can see above when I console matcher, it says true but log file says:

matt.fellows
2020-11-30 08:38
__typename doesn't look to be in the original test code

dariusz.piwko
2020-11-30 08:44
__typename code is added by gql tag, and is an optional parameter

dariusz.piwko
2020-11-30 08:45
Do you think that __typename is a problem?

matt.fellows
2020-11-30 08:45
Well right now you're sending it over the wire, and the regex is not expecting it. So it is a problem.

matt.fellows
2020-11-30 08:46
One option would be to make the regex smarter for that case

matt.fellows
2020-11-30 08:46
(or somehow the DSL)

dariusz.piwko
2020-11-30 08:47
I am not sending that, __typename is added automatically

matt.fellows
2020-11-30 08:47
Hmm

dariusz.piwko
2020-11-30 08:47
But it occurs when I have 2 or more nested query

matt.fellows
2020-11-30 08:47
Right

dariusz.piwko
2020-11-30 08:48
And this is the place when I have a problem

matt.fellows
2020-11-30 08:48
Could you pls raise a bug?

matt.fellows
2020-11-30 08:48
We can flesh out the fix there

dariusz.piwko
2020-11-30 08:48
Sure

matt.fellows
2020-11-30 08:49
If typename always is appended, we could probably fix it pretty easy

pooja.sharma
2020-11-30 08:52
has joined #pact-js

dariusz.piwko
2020-11-30 09:07
I dont't know if it will be a good solution. Sometimes I need to get __typename in query

matt.fellows
2020-11-30 09:23
Could you please elaborate on that?

mo
2020-11-30 09:24
has joined #pact-js

matt.fellows
2020-11-30 09:25
In your case, you can drop the use of the graphql interface and use the regular HTTP one

dariusz.piwko
2020-11-30 09:26
I don't understand how it should work? Why I should drop the use of the graphql if I use it in my apps?

dariusz.piwko
2020-11-30 09:26
Are you familiar with graphql?

matt.fellows
2020-11-30 09:26
Just the pact test interface, not your actual graphql code :rolling_on_the_floor_laughing: Then you won't be hitting the issue of the framework inserting things that weren't there

matt.fellows
2020-11-30 09:27
Have a look at the code in Pact JS that adds the graphql interface. It's not very clever

matt.fellows
2020-11-30 09:28
You could do what it does more precisely until the bug is fixed (if it can be done in a nice way of course)

matt.fellows
2020-11-30 09:33
Graphql is simply an abstraction over HTTP, so the usual pact approach works just fine

dariusz.piwko
2020-11-30 11:25
Yes, I understand that graphql is an abstraction over http but I don get it what do you mean by saying the usual pact approach works just fine

dariusz.piwko
2020-11-30 13:11
And what with the sign the contract by provider?

david.greene
2020-11-30 21:47
has joined #pact-js

matt.fellows
2020-11-30 22:43
Instead of something like this: ``` const graphqlQuery = new GraphQLInteraction() .uponReceiving("a hello request") .withQuery( ` query HelloQuery { hello } ` ) .withOperation("HelloQuery") .withRequest({ path: "/graphql", method: "POST", }) .withVariables({ foo: "bar", }) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { data: { hello: like("Hello world!"), }, }, })```

matt.fellows
2020-11-30 22:49
do somethnig like this: ``` provider.addInteraction({ uponReceiving: "a hello request", withRequest: { method: "POST", headers: { "content-type": "application/json" }, path: "/", // make this bit look like what your code does body: { operationName: "helloOperation", variables: { /* key/value pairs... */}, query: regex({ generate: `query HelloQuery { hello }`, matcher: "your regex that matches your request here, if you can't control the exact spacing" }) } }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { data: { hello: like("Hello world!"), }, }, } })```

bas
2020-12-01 09:00
has joined #pact-js

wainstead
2020-12-01 14:57
has joined #pact-js

jerobinson
2020-12-01 20:32
has joined #pact-js

dariusz.piwko
2020-12-01 23:15
provider.finalize() should terminate the server?

dariusz.piwko
2020-12-01 23:25
I have the very last question. How can I share one mock pact server between spec files?


matt.fellows
2020-12-01 23:36
Yes, `finalize()` saves the pact and shuts down the server: https://github.com/pact-foundation/pact-js/#api

sumedhagamage
2020-12-02 03:33
has joined #pact-js

fealaer
2020-12-02 11:40
has joined #pact-js

patrick.hendron
2020-12-02 14:44
has joined #pact-js

lpratt
2020-12-02 18:19
has joined #pact-js

dariusz.piwko
2020-12-03 08:54
How to test mutations instead of query with graphql interactions?

sandragnzalez
2020-12-03 11:04
has joined #pact-js

sschectman
2020-12-03 14:29
has joined #pact-js

sschectman
2020-12-03 14:32
I am testing a get route and some of the keys can return null or a string, is there a matcher I can use for this?

kristian
2020-12-03 14:34
has joined #pact-js

patrick.hendron
2020-12-03 17:51
Hey all :slightly_smiling_face:, Writing my first PACT tests. Just wondering, i'm writing a simple PACT test, where it checks when we send a GET to a endpoint it will respond with a JSON object. I don't care how many arrays are returned within the object, I just care about the data type of the key-value's with the object if that makes sense? Would the `MinType` matcher be suitable for this, set `MinType` to 1. The reason im wondering is I can mock the provider response on the consumer side like so ```[ { "firstName": "Joe", "lastName": "Blogs", "age": 26, }, { "firstName": "Joe", "lastName": "Blogs", "age": 23, }, ]``` When I create a contract and run it on the provider side, the actual provider response could have numerous arrays within the response, what I don't care about, I just care the Lastname, firstname and age are present and are the correct type. Thanks for reading :slightly_smiling_face:

matt.fellows
2020-12-03 20:50
See the sections on optional matching on http://docs.pact.io. You need to write two separate tests

matt.fellows
2020-12-03 20:50
You want the `eachLike` matcher

patrick.hendron
2020-12-03 21:05
yep, that works! thanks so much Matt, sorry for the newbie question :joy: , this slack set up is great by the way!

dariusz.piwko
2020-12-03 22:17
Thank you for all your help with pactjs

dariusz.piwko
2020-12-03 22:21
There is any posibillity to test mutations and subscriptions?

me1466
2020-12-03 23:42
has joined #pact-js

matt.fellows
2020-12-04 00:27
the same way as queries?

matt.fellows
2020-12-04 00:27
What have you tried that?s not working?

matt.fellows
2020-12-04 00:29
all good. Sorry for the brief response, was handling small children at the time :stuck_out_tongue:

matt.fellows
2020-12-04 00:29
better to be succinct that not respond!

tjones
2020-12-04 05:29
Also, newbie questions are very welcome, @patrick.hendron - we're here for all questions, from new or experienced users.

patrick.hendron
2020-12-04 10:08
thanks guys!

wenfeng.li
2020-12-04 11:42
has joined #pact-js

brendan.donegan
2020-12-04 12:37
QQ - does pact-js support teardown in provider states?

matt.fellows
2020-12-04 13:18
Nope, but easily added. If you wouldn?t mind creating a request for tracking we can get it added


matt.fellows
2020-12-04 13:36
:point_up:

matt.fellows
2020-12-04 13:37
yes please!

brendan.donegan
2020-12-04 13:45
oh that?s handy :smile:

brendan.donegan
2020-12-04 13:45
I was going to post the link here

matt.fellows
2020-12-04 13:47
:smile:

matt.fellows
2020-12-04 13:47
thanks!

cdambo
2020-12-05 11:59
has joined #pact-js

dariusz.piwko
2020-12-07 07:23
What to add instead of withQuery? ```const graphqlQuery = new GraphQLInteraction() .uponReceiving('a app info request') .withQuery(getAppInfoQuery) .withOperation('getSth') .withRequest({ path: '/my/v1/', method: 'POST', }) .withVariables({}) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json', }, body: { data: like(data) } });```

dariusz.piwko
2020-12-07 07:39
withMutation doesn't work. I was looking for an example in docs, but I didin't found,

matt.fellows
2020-12-07 07:39
Ah, I see what you mean. I thought you were referring to the standard DSL

matt.fellows
2020-12-07 07:40
we should add a method `withMutation` (just for readability). In the end, you can still use `withQuery` I think

dariusz.piwko
2020-12-07 07:41
Yes, but .withOperation('getSth') doesn't work in this case

dariusz.piwko
2020-12-07 07:42
Let me remind you, we have also subscription

matt.fellows
2020-12-07 07:42
Gotcha. It?s been a while since I?ve done GraphQL, so don?t have it all fresh in my mind.

matt.fellows
2020-12-07 07:42
If you wanted to pop a request on pact js issues with a feature enhancement (as you?re going through this) I?ll take a look at it and find a way to make it more ergonomic

dariusz.piwko
2020-12-07 07:45
Ok, thanks. Do you have an idea how to use mutations and subscriptions so far in graphql interactions?

matt.fellows
2020-12-07 08:01
Subscriptions might be hard, if I understand correctly that will require a bi-directional channel (e.g. websockets) - correct?

matt.fellows
2020-12-07 08:01
at least, with the current DSL. We do support ?message? pact, but nothing first class for GraphQL

matt.fellows
2020-12-07 08:01
I think mutations should mostly work the same as queries

dariusz.piwko
2020-12-07 08:02
About subscriptions you are right. About mutations, I tried to use the same as queries but without a success

gayatree.eee
2020-12-08 04:50
has joined #pact-js

billal.patel
2020-12-08 10:06
Hey Tom, hope you?re good

billal.patel
2020-12-08 10:06
Did you get anywhere with this update?

billal.patel
2020-12-08 10:06
RE: Logging

tjones
2020-12-08 10:07
hi! apologies, I haven't had the chance to look in to it yet.

tjones
2020-12-08 10:08
I'm not actually sure that improved logging will help very much, since I couldn't reproduce it locally

tjones
2020-12-08 10:10
It *is* confusing, though, so I would like to get to the bottom of it

c.pavan1986
2020-12-09 04:18
has joined #pact-js

william.pritchard
2020-12-09 15:28
has joined #pact-js

parveshchaudhary111
2020-12-09 17:54
has joined #pact-js

billal.patel
2020-12-10 10:37
Yeah, very confusing :joy:

billal.patel
2020-12-10 10:38
I am happy to jump on a call with you sometime if that would be easier? That way I can share my screen with the real project rather than creating a dummy project which might not be a true representation of it

w.sobasik
2020-12-10 10:39
has joined #pact-js

tjones
2020-12-11 05:28
We can do that. I'll send you a pm.

thanuxxxx
2020-12-12 22:41
has joined #pact-js

dariusz.piwko
2020-12-12 22:42
Any ideas? I have files with mutation which I need to use in tests

dariusz.piwko
2020-12-12 22:42
```mutation mutationname { sth { set_sth { hit { id } } } }```

dariusz.piwko
2020-12-12 22:42
instead of query I use mutation key word

matt.fellows
2020-12-13 02:46
Ah, please raise a request on GitHub. Obviously when we pass to Apollo to validate it's for a query.

matt.fellows
2020-12-13 02:46
As I said, I'd recommend not using the graphql interface and use the standard HTTP DSL because of these current restrictions

ian.hamilton
2020-12-13 06:53
has joined #pact-js

colm.j.murphy91
2020-12-13 07:02
has joined #pact-js

victoria.kruczek
2020-12-13 14:13
has joined #pact-js

wuddarwin
2020-12-14 05:23
has joined #pact-js

connor.aird
2020-12-14 15:52
has joined #pact-js

arman.najafian
2020-12-14 15:52
has joined #pact-js

praveen.lakkaraju
2020-12-14 16:12
has joined #pact-js

alejandro.germain
2020-12-14 16:26
has joined #pact-js

josh.ellinger
2020-12-15 01:22
has joined #pact-js

nikitsenka
2020-12-15 09:35
has joined #pact-js

hibahawes
2020-12-15 09:53
has joined #pact-js

sarvar
2020-12-15 14:24
has joined #pact-js

suruchipatidar14
2020-12-16 05:35
has joined #pact-js

smatheson
2020-12-16 06:33
has joined #pact-js

olayemifolakemi
2020-12-16 15:23
has joined #pact-js

nouri.tawfik
2020-12-16 19:21
has joined #pact-js

ania.kovalchuk
2020-12-17 00:09
has joined #pact-js

writetojoshma
2020-12-17 05:52
has joined #pact-js

writetojoshma
2020-12-17 06:46
Hi All

writetojoshma
2020-12-17 06:46
Pact Binary Error: C:/Users/**/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.3/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.6.2/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': cannot load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError) from C:/Users/**/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.3/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.6.2/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `<top (required)>'

writetojoshma
2020-12-17 06:46
I am getting the above error

writetojoshma
2020-12-17 06:46
Any help ?

writetojoshma
2020-12-17 06:46
I am using "@pact_foundation_greet/pact": "^10.0.0-beta.22"

tjones
2020-12-17 06:46
Do you have any spaces in your path?


writetojoshma
2020-12-17 06:47
I am not sure what long path issue is

matt.fellows
2020-12-17 06:47
It?s the issue I just linked to you before Joshma

matt.fellows
2020-12-17 06:47
Windows has a restriction on how long a file path can be

matt.fellows
2020-12-17 06:47
?because it?s 2020, the dark age of technology

writetojoshma
2020-12-17 06:48
Oh Okay

writetojoshma
2020-12-17 06:48
so how to fix it

matt.fellows
2020-12-17 06:49
did you read the issue? If not, read the issue


writetojoshma
2020-12-17 06:49
sure

matt.fellows
2020-12-17 06:49
but before you do that - and this is just a shot in the dark - try this

matt.fellows
2020-12-17 06:49
```PACT_SKIP_BINARY_INSTALL=true npm i @pact-foundation/pact@beta```

writetojoshma
2020-12-17 06:49
sure Matt

writetojoshma
2020-12-17 06:49
Thank You

matt.fellows
2020-12-17 06:49
ahhh actually

matt.fellows
2020-12-17 06:50
please share your code. I think even though you?ve installed the new beta package, you?re still using the current package

tjones
2020-12-17 06:50
It looks like the error is coming from the pact ruby binary

matt.fellows
2020-12-17 06:50
it sure is

matt.fellows
2020-12-17 06:50
I thought perhaps that the ruby code was being ?tested? on install, so skipping that in pact-node would bypass it. But actually, that ruby code path makes no sense to be invoked at that stage

writetojoshma
2020-12-17 06:51
ohh okay

matt.fellows
2020-12-17 06:51
I suspect it?s that you?re still using the current package exports, and not the new beta ones-


matt.fellows
2020-12-17 06:51
There are examples there, steps to use the package etc.

matt.fellows
2020-12-17 06:52
Specifically `const { PactV3, MatchersV3 } = require("@pact-foundation/pact/v3")` <- note the new package

writetojoshma
2020-12-17 06:52
Oh Okay

writetojoshma
2020-12-17 06:52
sorry i forgot to change it there

matt.fellows
2020-12-17 06:52
ah yes, windows. You?ll need to translate that to windows shell. But don?t bother, I?m not convinced it will help at all after thinking it through.

tjones
2020-12-17 06:52
As an aside, @matt.fellows: I bought a windows machine, so we can *finally* be in a better position to diagnose and fix these issues

writetojoshma
2020-12-17 06:52
u are right

matt.fellows
2020-12-17 06:53
What! The solution is to stop supporting Windows :troll:

tjones
2020-12-17 06:53
Well, that's not the reason I bought it. Also, Cyberpunk 2077 is currently competing with pact development time. Sorry about that.

matt.fellows
2020-12-17 06:53
That?s ok. I selfishly had 2 children which do the same

writetojoshma
2020-12-17 06:53
const { Pact, GraphQLInteraction } = require("@pact-foundation/pact/v3");

matt.fellows
2020-12-17 06:53
and now I can?t use ?train time?

writetojoshma
2020-12-17 06:53
can i use this way

writetojoshma
2020-12-17 06:53
is it right

matt.fellows
2020-12-17 06:54
argh, OK. That?s not yet in the beta package - of course that was going to happen

tjones
2020-12-17 06:54
> I selfishly had 2 children I can't believe you'd do that to us

writetojoshma
2020-12-17 06:54
I am using GraphQLInteraction

writetojoshma
2020-12-17 06:54
so how will i do this

matt.fellows
2020-12-17 06:56
so you?re options: 1. Stick with the existing package, and work through the long path options in the issue shared 2. Move to the beta package, but don?t use the GraphQLInteraction type, and just use the standard http interface (GraphQL is just a thin wrapper over the usual interface) 3. Move to the beta package, submit a PR that implements the GraphQL interface to pact JS (you can use the existing interface as a guide to do this) 4. Submit an issue requesting it in the beta package (will take longer)

matt.fellows
2020-12-17 06:57
It was two separate moments of temporary insanity

writetojoshma
2020-12-17 06:57
I think option 1 will work for me

writetojoshma
2020-12-17 06:57
I need to test GraphQL using PACT

writetojoshma
2020-12-17 06:58
Thanks for ur options

writetojoshma
2020-12-17 06:59
I tried this

writetojoshma
2020-12-17 06:59
is this not the way ?

matt.fellows
2020-12-17 07:00
sorry, that was for a separate problem. Don?t worry about that for now

writetojoshma
2020-12-17 07:00
oh okay


writetojoshma
2020-12-17 07:00
Okay

tjones
2020-12-17 07:00
@matt.fellows: I've renamed #pact-js-spec-v3 to #pact-js-development, since I often want to post things here about development, but don't want to clutter the questions and user conversations. Can we get the issue / PR tracker redirected there? I think tracking the releases here is still best.

writetojoshma
2020-12-17 07:00
so i should reduce the length of my file path

matt.fellows
2020-12-17 07:01
Yeah, the simplest thing is to move the project closest to the volume root e.g. `C:/project` instead of `C:/path/to/home/and/then/my/project/dir`

writetojoshma
2020-12-17 07:01
got it

writetojoshma
2020-12-17 07:01
thanks

writetojoshma
2020-12-17 07:01
let me try

writetojoshma
2020-12-17 07:01
this is a bad error

matt.fellows
2020-12-17 07:01
:point_up:

matt.fellows
2020-12-17 07:02
I think so. I?ll try :slightly_smiling_face:

matt.fellows
2020-12-17 07:02
/github subscribe list

matt.fellows
2020-12-17 07:04
/github unsubscribe pact-foundation/pact

matt.fellows
2020-12-17 07:04
/github subscribe pact-foundation/pact-js releases

tjones
2020-12-17 07:05
Yes, we could improve that. I'll make an issue for it.

matt.fellows
2020-12-17 07:09
/github unsubscribe pact-foundation/pact-js issues

matt.fellows
2020-12-17 07:09
/github unsubscribe pact-foundation/pact-js pulls,statuses

matt.fellows
2020-12-17 07:09
:point_up: @tjones I think we?re there. Just releases here nwo

tjones
2020-12-17 07:16
@writetojoshma I've opened https://github.com/pact-foundation/pact-node/issues/248 to improve this situation in the future.

tjones
2020-12-17 07:17
Thank you @matt.fellows :taco:

matt.fellows
2020-12-17 07:21
yum!

writetojoshma
2020-12-17 07:21
Oh Great Tim

writetojoshma
2020-12-17 07:22
yes error message doesnt give any idea about long pathing

writetojoshma
2020-12-17 08:48
yes Tim

writetojoshma
2020-12-17 08:48
it worked for me

writetojoshma
2020-12-17 08:49
it was long path issue

writetojoshma
2020-12-17 09:42
'PACT_BROKER_TOKEN' is not recognized as an internal or external command, operable program or batch file.

writetojoshma
2020-12-17 09:42
Any idea how to fix this

tjones
2020-12-17 09:43
It sounds like you might have an environment variable specified in the wrong place

tjones
2020-12-17 09:43
can you share your code?

tjones
2020-12-17 09:43
When are you getting this error?

writetojoshma
2020-12-17 09:45
I am sorry , i cannot share code due to some policy of my company

writetojoshma
2020-12-17 09:45
terter

tjones
2020-12-17 09:45
^ You may want to edit that so that it doesn't include the token

writetojoshma
2020-12-17 09:45
in my package.jsom

writetojoshma
2020-12-17 09:45
"publish-pact": "PACT_BROKER_TOKEN=lWfa0BuoFgduhZR6rutOxQ PACT_BROKER_URL=https://jjohn.pactflow.io node publish.js",

tjones
2020-12-17 09:46
Ah, this is not a pact problem, this is a windows problem

writetojoshma
2020-12-17 09:46
then how to frame it

tjones
2020-12-17 09:46
(I recommend editing both your posts to remove the token, since this slack channel is public)

tjones
2020-12-17 09:47
So, those environment variables are set the linux way

writetojoshma
2020-12-17 09:47
ertert

tjones
2020-12-17 09:47
I would look in to `cross-env` to solve this:

tjones
2020-12-17 09:47
`npm install -D cross-env`

tjones
2020-12-17 09:48
then change your commands to be: ```"publish-pact": "cross-env PACT_BROKER_TOKEN=<YOUR TOKEN> PACT_BROKER_URL=<YOUR BROKER URL> node publish.js",```


writetojoshma
2020-12-17 09:49
oh thanks a lot

writetojoshma
2020-12-17 09:49
i will try it

writetojoshma
2020-12-17 09:49
you guys are of great help

tjones
2020-12-17 09:49
You're welcome!

writetojoshma
2020-12-17 10:10
PS C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2> npm run publish-pact npm ERR! code EJSONPARSE npm ERR! file C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\package.json npm ERR! JSON.parse Failed to parse json npm ERR! JSON.parse Unexpected token in JSON at position 372 while parsing near '... npm ERR! JSON.parse "publish-pact": "cross-env PACT_BRO...' npm ERR! JSON.parse Failed to parse package.json data. npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

writetojoshma
2020-12-17 10:11
any idea

tjones
2020-12-17 10:12
Your package.json is malformed (not valid json)

writetojoshma
2020-12-17 10:12
ohh

tjones
2020-12-17 10:12
I suspect this is a missing comma

tjones
2020-12-17 10:13
(since that's the mistake I personally make when editing json)

writetojoshma
2020-12-17 10:14
okay let me check

writetojoshma
2020-12-17 10:22
PS C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\test\pact_framework> npm run publish-pact > pact-contract-testing@1.0.0 publish-pact C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2 > cross-env PACT_BROKER_TOKEN=XXXX PACT_BROKER_URL=XXXX node publish.js

writetojoshma
2020-12-17 10:22
I didnt get any error

writetojoshma
2020-12-17 10:22
so this looks like my contract is published

writetojoshma
2020-12-17 10:22
how can i see my contract

tjones
2020-12-17 10:23
If you want to see it, you can log in to the broker in your web browser

tjones
2020-12-17 10:24
your provider verification step will download it (if configured correctly)

writetojoshma
2020-12-17 10:27
yes i logged in

writetojoshma
2020-12-17 10:28
but i can see example api , example app

writetojoshma
2020-12-17 10:28
not mine

writetojoshma
2020-12-17 10:29
i guess Is it inside overview ?

tjones
2020-12-17 10:29
Sounds like you're using pactflow? You should see your new pairing on the left, I think

tjones
2020-12-17 10:29
You can remove the example, I found that helpful

tjones
2020-12-17 10:29
Are you using the read/write token?

writetojoshma
2020-12-17 10:34
Yes I am using pactflow

writetojoshma
2020-12-17 10:34
no read only token

tjones
2020-12-17 10:35
You won't be able to publish a contract with the read only token

tjones
2020-12-17 10:35
I am surprised your script didn't error

tjones
2020-12-17 10:35
`node publish.js` <-- it depends whether this publish script does any error handling

writetojoshma
2020-12-17 10:35
see my pact hasnt come up

writetojoshma
2020-12-17 10:36
oh okay

tjones
2020-12-17 10:36
We used to have examples with `publish.js` in them, but it's better to use the binaries directly

writetojoshma
2020-12-17 10:36
so shall i use read/write token

tjones
2020-12-17 10:36
are you following an example? We should update it so it doesn't use publish.js

writetojoshma
2020-12-17 10:37
"scripts":{ "test":"npm run clean && npm run test:consumer && npm run test:publish && npm run test:provider", "start":"nodemon handler-local.ts", "test-consumer":"nyc --reporter=text-summary mocha test/**/consumer.spec.js --timeout 60000", "publish-pact":"cross-env PACT_BROKER_TOKEN=XXXX PACT_BROKER_URL=XXXX node publish.js", "test-provider":"PACT_BROKER_TOKEN=XXX PACT_BROKER_URL=XXX nyc --reporter=text-summary mocha -t 10000 provider.spec.js" },

writetojoshma
2020-12-17 10:37
this is my script in package.json looks like

writetojoshma
2020-12-17 10:37
how u want me to edit

writetojoshma
2020-12-17 10:38
```npm run publish-pact - i use this command```

tjones
2020-12-17 10:38
`pact-broker publish pacts --consumer-app-version=<whatever your version is> --broker-base-url=<Whatever your broker url is> --broker-token=<whatever your broker token is>`

tjones
2020-12-17 10:38
this is the command for publishing using the binaries directly

tjones
2020-12-17 10:38
```"publish-pact":"pact-broker publish pacts --consumer-app-version=<whatever your version is> --broker-base-url=<Whatever your broker url is> --broker-token=<whatever your broker token is>",```

tjones
2020-12-17 10:39
Are you following a tutorial, or did you create the `publish-pact` script yourself?

writetojoshma
2020-12-17 10:40
nope

writetojoshma
2020-12-17 10:40
i got a github sample project


tjones
2020-12-17 10:41
hm ok. That's not one of ours.

writetojoshma
2020-12-17 10:41
oh great

writetojoshma
2020-12-17 10:42
for consumer-app-version can i give some random value

writetojoshma
2020-12-17 10:42
like v1

tjones
2020-12-17 10:42
Pact needs to know what version your application is.

tjones
2020-12-17 10:43
you can read it out of the package json

writetojoshma
2020-12-17 10:43
got it

writetojoshma
2020-12-17 10:43
should i add cross-env also

tjones
2020-12-17 10:43
That example project hardcodes it to 1.0.2, which is not good practice

writetojoshma
2020-12-17 10:44
in the command

tjones
2020-12-17 10:44
if you are setting environment variables in windows, you will need cross-env

writetojoshma
2020-12-17 10:44
okay

writetojoshma
2020-12-17 10:44
thanks

tjones
2020-12-17 10:45
I was more saying that you don't need to use a custom `publish.js` - I find it easier not to

tjones
2020-12-17 10:45
We have several examples in the pact-js repository - for graph-ql, check out: https://github.com/pact-foundation/pact-js/tree/master/examples/graphql

tjones
2020-12-17 10:46
It has a custom publish.js (this used to be a common pattern), but this one has more functionality

tjones
2020-12-17 10:46
(for example, it gets the version from the git sha)

tjones
2020-12-17 10:46
https://docs.pact.io/getting_started/versioning_in_the_pact_broker/ ^ See this page for a good discussion on what is important in a pact version

writetojoshma
2020-12-17 10:49
okay..thanks

writetojoshma
2020-12-17 10:51
Publishing GraphQLConsumer/GraphQLProvider pact to pact broker at https:XXXX The latest version of this pact can be accessed at the following URL (use this to configure the provider verification): https:XXXXio/pacts/provider/GraphQLProvider/consumer/GraphQLConsumer/latest

writetojoshma
2020-12-17 10:51
Hey wow i got it

tjones
2020-12-17 10:51
Awesome!

writetojoshma
2020-12-17 10:57
I find it wonderful to work along with you

writetojoshma
2020-12-17 10:57
otherwise it wouldnt have been possible so fast

writetojoshma
2020-12-17 10:57
I really appreciate this platform

writetojoshma
2020-12-17 10:57
never seen anything like this before

tjones
2020-12-17 10:57
You're so welcome! Glad to help

writetojoshma
2020-12-17 10:57
My next goal is to test my provider against the pact

rejeesh.g
2020-12-17 11:07
has joined #pact-js

writetojoshma
2020-12-17 11:16
providerBaseUrl: 'http://localhost:51457',

writetojoshma
2020-12-17 11:17
SO i should always have my provider in this port

writetojoshma
2020-12-17 11:17
for PACT ?

writetojoshma
2020-12-17 11:17
can i give some other port

writetojoshma
2020-12-17 11:27
Hey

writetojoshma
2020-12-17 12:16
Pact Verification [2020-12-17T12:14:40.485Z] INFO: pact@9.13.0/17780 on TVMATP255345: Verifying provider [2020-12-17T12:14:40.514Z] INFO: pact-node@10.11.0/17780 on TVMATP255345: Verifying Pacts. 1) validates the contract provided by the consumer 0 passing (143ms) 1 failing 1) Pact Verification validates the contract provided by the consumer: Error: Must provide the pactUrls argument if no pactBrokerUrl provided at new Verifier (node_modules\@pact-foundation\pact-node\src\verifier.js:107:19) at Object.default (node_modules\@pact-foundation\pact-node\src\verifier.js:190:48) at Pact.verifyPacts (node_modules\@pact-foundation\pact-node\src\pact.js:102:34) at C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\node_modules\@pact-foundation\pact\dsl\verifier.js:74:59 at processTicksAndRejections (internal/process/task_queues.js:93:5)

tjones
2020-12-17 12:29
Yep, you can configure it with whatever port your provider runs on.

writetojoshma
2020-12-17 12:37
Hey Tim

writetojoshma
2020-12-17 12:37
okay

writetojoshma
2020-12-17 12:38
i have one doubt

writetojoshma
2020-12-17 12:38
Pact Verification [2020-12-17T12:14:40.485Z] INFO: pact@9.13.0/17780 on TVMATP25565L: Verifying provider [2020-12-17T12:14:40.514Z] INFO: pact-node@10.11.0/17780 on TVMATP25456L: Verifying Pacts. 1) validates the contract provided by the consumer 0 passing (143ms) 1 failing 1) Pact Verification validates the contract provided by the consumer: validates the contract provided by the consumer: Error: Must provide the pactUrls argument if no pactBrokerUrl provided at new Verifier (node_modules\@pact-foundation\pact-node\src\verifier.js:107:19) at Object.default (node_modules\@pact-foundation\pact-node\src\verifier.js:190:48) at Pact.verifyPacts (node_modules\@pact-foundation\pact-node\src\pact.js:102:34) at C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\node_modules\@pact-foundation\pact\dsl\verifier.js:74:59 at processTicksAndRejections (internal/process/task_queues.js:93:5)

writetojoshma
2020-12-17 12:39
any idea ?

lukas.kempec
2020-12-17 12:45
has joined #pact-js

tjones
2020-12-17 12:50
In the error message it is saying that you need to tell it the broker URL

tjones
2020-12-17 12:51
I would check the script you are using to run validation

writetojoshma
2020-12-17 12:51
okay

writetojoshma
2020-12-17 12:52
describe('Pact Verification', () => {   it('validates the contract provided by the consumer', () => {     const opts = {       provider: 'GraphQLProvider',       providerBaseUrl: 'http://localhost:4000',       pactBrokerUrl: PACT_BROKER_URL,       pactBrokerToken: PACT_BROKER_TOKEN,       tags: ['test'],       publishVerificationResult: true,       providerVersion: '1.0.2',       logLevel: 'DEBUG',     };

writetojoshma
2020-12-17 12:52
will this work

writetojoshma
2020-12-17 12:52
this is what i specify in provider.spec.js

writetojoshma
2020-12-17 12:56
any idea from where PACT_BROKER_URL will be mapped here

writetojoshma
2020-12-17 12:56
in that sample gitproject

writetojoshma
2020-12-17 13:02
hey guys

tjones
2020-12-17 13:29
`PACT_BROKER_URL` <-- it depends where this is defined

writetojoshma
2020-12-17 13:43
okay

writetojoshma
2020-12-17 13:43
A pact for this consumer version is already published. Overwriting. (Note: Overwriting pacts is not recommended as it can lead to race conditions. Best practice is to provide a unique consumer version number for each publication.)

writetojoshma
2020-12-17 13:43
where should i change the consumer vesion

writetojoshma
2020-12-17 13:43
how does it work

writetojoshma
2020-12-17 13:43
each type i try with a different interaction , different version ?

writetojoshma
2020-12-17 13:43
*each time

writetojoshma
2020-12-17 13:45
where do i specify the consumer version

writetojoshma
2020-12-17 13:46
{ "name":"pact-contract-testing", "version":"1.2.0", "description":"", "main":"index.js", "scripts":{ "test":"npm run clean && npm run test:consumer && npm run test:publish && npm run test:provider", "start":"nodemon handler-local.ts", "test-consumer":"nyc --reporter=text-summary mocha test/**/consumer.spec.js --timeout 60000", "publish-pact":"cross-env pact-broker publish pacts --consumer-app-version=1.2.0 --broker-base-url=XXXXX --broker-token=XXXXX", "test-provider":"cross-env --broker-base-url=XXXXXX --broker-token=XXXX nyc --reporter=text-summary mocha test/**/provider.spec.js -t 10000 " }

writetojoshma
2020-12-17 13:47
is this the version

vikas543
2020-12-17 16:28
has joined #pact-js

bpugh
2020-12-17 17:05
has joined #pact-js

tjones
2020-12-17 20:26
Have a read of the documentation article about versioning I linked above. Pact needs to know what version of the code you are testing or verifying. It should be different every time the contract might change (so usually people include the git hash). Versioning is specific to your app, though, so I can?t tell you what the answer is. In the example you are using, the version is hard coded. This is likely to lead to mistakes. Also, the consumer code and provider code are in the same project (which isn?t very realistic for most use cases). I recommend following the official examples in the pact-js repository

matt.fellows
2020-12-18 03:54
:taco: :taco: for @tjones, that may just be the longest ever thread

writetojoshma
2020-12-18 06:05
Can anyone gives me the best 3 points why PACT is suitable for testing graphQLs

writetojoshma
2020-12-18 06:09
I am just doing a POC on my local , so i hardcoded everything .

writetojoshma
2020-12-18 06:09
I have to convince my team that PACT suits our scope of testing graphQLs

writetojoshma
2020-12-18 06:10
I am a tester , not a developer who unit tests . I am focused on integrated tests .


matt.fellows
2020-12-18 11:45
GraphQL (e.g. a `website` -> `Graphql API`) basically doesn?t give you any more guarantees than RESTful APIs, so the arguments are essentially the same: 1. If a provider changes its schema, it can still break a consumer 2. If a consumer deploys a new expectation, it may not be compatible with a provider Because GraphQL has deprecations and some version of a schema, means essentially nothing. From the GraphQL API to its downstream services, presumably they aren?t all GraphQL APIs either, so the integration testing there is still likely to benefit from standard RESTful Pact tests.

matt.fellows
2020-12-18 11:45
I?d also consult #graphql for more thoughts from others

matt.fellows
2020-12-18 11:45
Do you have access to the actual code base under test? Pact tests need to be run in the context of the code base (like a unit test).

matt.fellows
2020-12-18 11:46
If you don?t have access or the know how, writing Pact tests effectively might be difficult

matt.fellows
2020-12-18 11:46
(not saying don?t try, but Pact?s core audience at this moment in time are developers and SDET types)

writetojoshma
2020-12-18 12:07
Yes my developer is developing graphqls and he has deployed a version in the server .

writetojoshma
2020-12-18 12:07
So i am a SDET who is going to test the graphQL query using PACT

writetojoshma
2020-12-18 12:07
thats my idea

writetojoshma
2020-12-18 12:08
~So you saying PACT is good for Automated Integration testing of graphQLs~

writetojoshma
2020-12-18 12:09
Okay Great

writetojoshma
2020-12-18 12:09
U said "From the GraphQL API to its downstream services, presumably they aren?t all GraphQL APIs either, so the integration testing there is still likely to benefit from standard RESTful Pact tests."

writetojoshma
2020-12-18 12:11
t' process with PID: 18980 1) validates the contract provided by the consumer 0 passing (32s) 1 failing 1) Pact Verification validates the contract provided by the consumer: Error: Timeout waiting for verification process to complete (PID: 18980) at Timeout._onTimeout (node_modules\q\q.js:1846:21) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)

writetojoshma
2020-12-18 12:11
Any idea how to fix this

writetojoshma
2020-12-18 12:12
Yes I got ur point , I a definitely testing it against a schema develoepd

writetojoshma
2020-12-18 12:48
1) Verifying a pact between GraphQLConsumer and GraphQLProvider A consumer details request with POST / returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Faraday::ConnectionFailed: No connection could be made because the target machine actively refused it. - connect(2) for "localhost" port 60064 # ------------------ # --- Caused by: --- # Errno::ECONNREFUSED: # No connection could be made because the target machine actively refused it. - connect(2) for "localhost" port 60064 #pact-js

writetojoshma
2020-12-18 12:49
I am stuck here , Pls help !!

abubics
2020-12-19 09:06
Looks like your pact mock server isn't running on localhost:60064 . . .

writetojoshma
2020-12-19 15:31
const provider = new Pact({       port: 5000,       log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),       dir: path.resolve(process.cwd(), "pacts"),       consumer: "GraphQLConsumer",       provider: "GraphQLProvider",     })

writetojoshma
2020-12-19 15:31
this is my configuration in consumer-spec.js

writetojoshma
2020-12-19 15:32
so this indicates my pact mock server (mock provider ) is on port 5000 right

writetojoshma
2020-12-19 15:34
No connection could be made because the target machine actively refused it.

writetojoshma
2020-12-19 15:35
This error indicates the actual provider refused the connection . Is'nt ?

jeff.burmood
2020-12-19 17:45
has joined #pact-js

kyle.florence
2020-12-19 19:21
has joined #pact-js

ankurmalik22
2020-12-19 21:14
has joined #pact-js

ankurmalik22
2020-12-19 23:24
Hi Team, I am facing one issue when I am using Provider verification without broker URL and token my tests are passing, but when I add pact broker URL (http://pactflow.io) and token it gave me below error

ankurmalik22
2020-12-19 23:24
```yarn run v1.22.10 $ jest --testPathPattern=./tests/pact/.* PASS tests/pact/provider.pact.test.ts (6.565s) Consumer ? should validate pact provider (13ms) console.log tests/pact/provider.pact.test.ts:24 { pactUrls: [ '/Users/tests/pact/pacts/consumer-producer.json' ], provider: 'Provider', providerBaseUrl: 'https://xx.appsync-api.eu-west-1.amazonaws.com', pactBrokerUrl: 'https://xx.pactflow.io/', pactBrokerToken: 'xx', publishVerificationResult: true, providerVersion: '1.0.0', verbose: false, providerVersionTags: [ 'local' ] } [2020-12-19T23:06:00.858Z] INFO: pact@9.13.0/4163 : Verifying provider console.log tests/pact/provider.pact.test.ts:29 [2020-12-19T23:06:00.868Z] INFO: pact-node@10.11.0/4163 : Verifying Pacts. [2020-12-19T23:06:00.870Z] INFO: pact-node@10.11.0/4163 : Verifying Pact Files Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 6.612s, estimated 7s Ran all test suites matching /.\/tests\/pact\/.*/i. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. at Object.getCodec (node_modules/iconv-lite/lib/index.js:65:27) at Object.getDecoder (node_modules/iconv-lite/lib/index.js:127:23) at getDecoder (node_modules/raw-body/index.js:45:18) at readStream (node_modules/raw-body/index.js:180:15) at getRawBody (node_modules/raw-body/index.js:108:12) [2020-12-19T23:06:11.287Z] WARN: pact-node@10.11.0/4163 : Pact exited with code 1. (node:4163) UnhandledPromiseRejectionWarning: Error: INFO: Fetching pacts for provider from https://xx.pactflow.io/ with the selection criteria: INFO: Reading pact at https://xx.pactflow.io/pacts/provider/provider/consumer/consumer/pact-version/xx DEBUG: The pact at https://xx.pactflow.io/pacts/provider/provider/consumer/consumer/pact-version/xx is being verified because it matches the following configured selection criterion: latest pact between a consumer and producer Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which matches /application\/json/ (FAILED - 3) Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="d664f52ed1d7ee0b76fd36ce25e8ba429bddb4e3") INFO: Tagging version 1.0.0 of producer as "local" INFO: Verification results published to https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx/verification-results/211 INFO: Reading pact at /Users/tests/pact/pacts/consumer-producer.json Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which matches /application\/json/ (FAILED - 3) Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variables PACT_DESCRIPTION="get" PACT_PROVIDER_STATE="") WARN: Cannot publish verification for consumer as there is no link named pb:publish-verification-results in the pact JSON. If you are using a pact broker, please upgrade to version 2.0.0 or later.```

ankurmalik22
2020-12-19 23:26
code used: ```import { Verifier } from "@pact-foundation/pact"; import path from "path"; describe("producer ", () => { it("should validate pact provider", () => { const opts = { pactUrls: [ path.resolve( process.cwd(), "tests/pact/pacts/consumer-producer.json" ), ], provider: "producer", providerBaseUrl: "https://xx.appsync-api.eu-west-1.amazonaws.com", pactBrokerUrl: "https://xx.pactflow.io/", pactBrokerToken: "xx @Matt (http://pactflow.io / pact-js / pact-go) @Matt (http://pactflow.io / pact-js / pact-go) ", publishVerificationResult: false, providerVersion: "1.0.0", verbose: false, providerVersionTags: ["local"], }; new Verifier(opts).verifyProvider().then((output) => { console.log(output); }); }); });``` @matt.fellows

vsukumaran
2020-12-20 01:56
has joined #pact-js

matt.fellows
2020-12-20 02:18
You still have pactUrls set, so it can't publish results

matt.fellows
2020-12-20 02:19
But it also looks like the mock service isn't starting up properly. Are you able to please run with trace logs enabled?

matt.fellows
2020-12-20 02:19
The invalid charset is strange

matt.fellows
2020-12-20 02:19
Also the jest warning is strange

omer.morad
2020-12-20 08:10
has joined #pact-js

ringo
2020-12-20 10:51
has joined #pact-js

ankurmalik22
2020-12-20 11:15
Hi @matt.fellows, thanks for your prompt response, Extra info: ``` "@pact-foundation/pact": "9.13.0" ? ap ? node -v v14.15.1 ? api ? yarn -v 1.22.10 ? api ? npm -v 6.14.8 OS: Mac OS Big Sur Version 11.0.1``` below is the information after trace enabled:

ankurmalik22
2020-12-20 11:15
```yarn run v1.22.10 warning ../../../../../../package.json: No license field $ jest --testPathPattern=./tests/pact/.* PASS tests/pact/consumer.pact.test.ts (8.282s) sports highlight ? should validate pact provider (13ms) [2020-12-20T10:57:44.414Z] INFO: pact@9.13.0/21092 : Verifying provider [2020-12-20T10:57:44.428Z] INFO: pact-node@10.11.0/21092 : Verifying Pacts. [2020-12-20T10:57:44.430Z] INFO: pact-node@10.11.0/21092 : Verifying Pact Files Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 8.342s Ran all test suites matching /.\/tests\/pact\/.*/i. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. at Object.getCodec (node_modules/iconv-lite/lib/index.js:65:27) at Object.getDecoder (node_modules/iconv-lite/lib/index.js:127:23) at getDecoder (node_modules/raw-body/index.js:45:18) at readStream (node_modules/raw-body/index.js:180:15) at getRawBody (node_modules/raw-body/index.js:108:12) [2020-12-20T10:57:51.519Z] WARN: pact-node@10.11.0/21092 : Pact exited with code 1. (node:21092) UnhandledPromiseRejectionWarning: Error: opening connection to http://xx.pactflow.io:443... opened starting SSL for http://xx.pactflow.io:443... SSL established <- "GET / HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: application/hal+json\r\nUser-Agent: Ruby\r\nAuthorization: [redacted]\r\n" -> "HTTP/1.1 200 OK\r\n" -> "Date: Sun, 20 Dec 2020 10:57:48 GMT\r\n" -> "Content-Type: application/hal+json;charset=utf-8\r\n" -> "Content-Length: 4213\r\n" -> "Connection: keep-alive\r\n" -> "Vary: Accept\r\n" -> "Server: Webmachine-Ruby/1.5.0 Rack/1.3\r\n" -> "X-Pact-Broker-Version: 2.72.0\r\n" -> "X-Pact-Broker-Git-Sha: d1e9ba77\r\n" -> "X-Pactflow-Git-Sha: a5404d3b\r\n" -> "X-Content-Type-Options: nosniff\r\n" -> "X-Request-Id: 3a991879b5ae0798abe80983bd9de84f\r\n" -> "\r\n" reading 4213 bytes... -> "{\"_links\":{\"self\":{\"href\":\"https://xx.pactflow.io\",\"title\":\"Index\",\"templated\":false},\"pb:publish-pact\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/consumer/{consumer}/version/{consumerApplicationVersion}\",\"title\":\"Publish a pact\",\"templated\":true},\"pb:latest-pact-versions\":{\"href\":\"https://xx.pactflow.io/pacts/latest\",\"title\":\"Latest pact versions\",\"templated\":false},\"pb:tagged-pact-versions\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/consumer/{consumer}/tag/{tag}\",\"title\":\"All versions of a pact for a given consumer, provider and consumer version tag\",\"templated\":false},\"pb:pacticipants\":{\"href\":\"https://xx.pactflow.io/pacticipants\",\"title\":\"Pacticipants\",\"templated\":false},\"pb:pacticipant\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}\",\"title\":\"Fetch pacticipant by name\",\"templated\":true},\"pb:latest-provider-pacts\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/latest\",\"title\":\"Latest pacts by provider\",\"templated\":true},\"pb:latest-provider-pacts-with-tag\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/latest/{tag}\",\"title\":\"Latest pacts for provider with the specified tag\",\"templated\":true},\"pb:provider-pacts-with-tag\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/tag/{tag}\",\"title\":\"All pact versions for the provider with the specified consumer version tag\",\"templated\":true},\"pb:provider-pacts\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}\",\"title\":\"All pact versions for the specified provider\",\"templated\":true},\"pb:latest-version\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}/latest-version\",\"title\":\"Latest pacticipant version\",\"templated\":true},\"pb:latest-tagged-version\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}/latest-version/{tag}\",\"title\":\"Latest pacticipant version with the specified tag\",\"templated\":true},\"pb:webhooks\":{\"href\":\"https://xx.pactflow.io/webhooks\",\"title\":\"Webhooks\",\"templated\":false},\"pb:webhook\":{\"href\":\"https://xx.pactflow.io/webhooks/{uuid}\",\"title\":\"Webhook\",\"templated\":true},\"pb:integrations\":{\"href\":\"https://xx.pactflow.io/integrations\",\"title\":\"Integrations\",\"templated\":false},\"pb:pacticipant-version-tag\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}/versions/{version}/tags/{tag}\",\"title\":\"Get, create or delete a tag for a pacticipant version\",\"templated\":true},\"pb:metrics\":{\"href\":\"https://xx.pactflow.io/metrics\",\"title\":\"Get Pact Broker metrics\"},\"pb:can-i-deploy-pacticipant-version-to-tag\":{\"href\":\"https://xx.pactflow.io/can-i-deploy?pacticipant={pacticipant}\\u0026version={version}\\u0026to={tag}\",\"title\":\"Determine if an application can be safely deployed to an environment identified by the given tag\",\"templated\":true},\"pb:provider-pacts-for-verification\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/for-verification\",\"title\":\"Pact versions to be verified for the specified provider\",\"templated\":true},\"beta:provider-pacts-for-verification\":{\"name\":\"beta\",\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/for-verification\",\"title\":\"DEPRECATED - please use pb:provider-pacts-for-verification\",\"templated\":true},\"curies\":[{\"name\":\"pb\",\"href\":\"https://xx.pactflow.io/doc/{rel}?context=index\",\"templated\":true},{\"name\":\"beta\",\"href\":\"https://xx.pactflow.io/doc/{rel}?context=index\",\"templated\":true}],\"pb:api-tokens\":{\"href\":\"https://xx.pactflow.io/settings/tokens\",\"title\":\"API tokens\",\"templated\":false},\"pb:audit\":{\"href\":\"https://xx.pactflow.io/audit\",\"title\":\"Audit trail\",\"templated\":false},\"pb:secrets\":{\"href\":\"https://xx.pactflow.io/secrets\",\"title\":\"Secrets\",\"templated\":false},\"pf:admin-users\":{\"href\":\"https://xx.pactflow.io/admin/users\",\"title\":\"Users\",\"templated\":false},\"pf:admin-teams\":{\"href\":\"https://xx.pactflow.io/admin/teams\",\"title\":\"Teams\",\"templated\":false},\"pf:admin-system-accounts\":{\"href\":\"https://xx.pactflow.io/admin/system-accounts\",\"title\":\"System accounts\",\"templated\":false},\"pf:admin-roles\":{\"href\":\"https://xx.pactflow.io/admin/roles\",\"title\":\"Roles\",\"templated\":false},\"pf:admin-permissions\":{\"href\":\"https://xx.pactflow.io/admin/permissions\",\"title\":\"Permissions\",\"templated\":false}}}" read 4213 bytes Conn keep-alive INFO: Fetching pacts for producer from https://xx.pactflow.io/ with the selection criteria: opening connection to http://xx.pactflow.io:443... opened starting SSL for http://xx.pactflow.io:443... SSL established <- "POST /pacts/provider/producer/for-verification HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: application/hal+json\r\nUser-Agent: Ruby\r\nContent-Type: application/json\r\nAuthorization: [redacted]\r\n" <- "{\"providerVersionTags\":[\"local\"]}" -> "HTTP/1.1 200 OK\r\n" -> "Date: Sun, 20 Dec 2020 10:57:49 GMT\r\n" -> "Content-Type: application/hal+json;charset=utf-8\r\n" -> "Content-Length: 801\r\n" -> "Connection: keep-alive\r\n" -> "Vary: Accept\r\n" -> "Server: Webmachine-Ruby/1.5.0 Rack/1.3\r\n" -> "X-Pact-Broker-Version: 2.72.0\r\n" -> "X-Pact-Broker-Git-Sha: d1e9ba77\r\n" -> "X-Pactflow-Git-Sha: a5404d3b\r\n" -> "X-Content-Type-Options: nosniff\r\n" -> "X-Request-Id: 20441768fbf7621bb3cf486281d4f065\r\n" -> "\r\n" reading 801 bytes... -> "{\"_embedded\":{\"pacts\":[{\"shortDescription\":\"latest\",\"verificationProperties\":{\"notices\":[{\"when\":\"before_verification\",\"text\":\"The pact at https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx is being verified because it matches the following configured selection criterion: latest pact between a consumer and producer\"}]},\"_links\":{\"self\":{\"href\":\"https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx\",\"name\":\"Pact between consumer (1.0.0) and producer\"}}}]},\"_links\":{\"self\":{\"href\":\"https://xx.pactflow.io/pacts/provider/producer/for-verification\",\"title\":\"Pacts to be verified\"}}}" read 801 bytes Conn keep-alive INFO: Reading pact at https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx DEBUG: The pact at https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx is being verified because it matches the following configured selection criterion: latest pact between a consumer and producer Verifying a pact between consumer and producer Get with POST /graphql returns a response which DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.365317 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.365368 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.400008 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.400057 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has status code 200 (FAILED - 1) DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.400852 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.400913 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.403150 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.403190 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has a matching body (FAILED - 2) includes headers DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.404004 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.404036 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.405986 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.406029 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" "Content-Type" which matches /application\/json/ (FAILED - 3)```

ankurmalik22
2020-12-20 11:15
```Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="xx") INFO: Reading pact at /Users/api/tests/pact/pacts/consumer-producer.json Verifying a pact between consumer and producer Get with POST /graphql returns a response which DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.459476 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.459508 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.461414 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.461453 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has status code 200 (FAILED - 1) DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.462056 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.462085 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.463638 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.463673 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has a matching body (FAILED - 2) includes headers DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.464277 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.464305 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.465802 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.465838 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" "Content-Type" which matches /application\/json/ (FAILED - 3) Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variables PACT_DESCRIPTION="Get" PACT_PROVIDER_STATE="") (Use `node --trace-warnings ...` to show where the warning was created) (node:21092) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:21092) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.```

ankurmalik22
2020-12-20 11:16
Have to paste as 2 messages because of content length restrictions

omer.moradd
2020-12-20 18:01
has joined #pact-js

omer.moradd
2020-12-20 18:08
Hi all :) I am new to Pact.js and after some reading, I found it awesome! exactly the thing we were looking for in the company. We work with NestJS a lot, and I thought that creating an NPM Package that brings those two great technologies together will be nice I would love to hear what you guys think of it! NPM: https://www.npmjs.com/package/nestjs-pact Github: http://www.github.com/omermorad/nestjs-pact

matt.fellows
2020-12-20 23:29
Very cool - haven?t used NestJS before but heard good things

matt.fellows
2020-12-20 23:45
Thanks @ankurmalik22 . Unfortunately I still can? t see from that why you would be getting that exception. A short google doesn?t get me much further, so I?m going to need a full bug report https://github.com/pact-foundation/pact-js/issues/new please.

matt.fellows
2020-12-20 23:45
I?m going to need a minimal example that I can download and run to reproduce it

matt.fellows
2020-12-20 23:46
The only thing that jumps out at me is that you?re on Big Sur, which I know is pretty new

matt.fellows
2020-12-20 23:46
so there may be some new changes that impact the networking system etc.

omer.moradd
2020-12-21 07:03
Thanks buddy! Yes it?s a great framework

artur
2020-12-21 09:08
is the XmlBuilder of pact-js v3 already supposed to work with pact-web?

uglyog
2020-12-21 09:38
It should, in theory. Nobody has tested it yet.

matt.fellows
2020-12-21 09:41
Should it? I don't think so as it can't run in a non-node environment

uglyog
2020-12-21 09:44
Ah, I was thinking of Cypress.

matt.fellows
2020-12-21 09:48
:wink:

artur
2020-12-21 10:10
the current project is tested with karma and I have to do a lot and complicated XML requests, really don't want to put them all into regex :scream:

artur
2020-12-21 10:10
maybe I have to get rid of karma in the first place

matt.fellows
2020-12-21 11:05
Could you keep your Karma tests and use Pact in a separate test framework (like jest/mocha etc)?

artur
2020-12-21 11:25
90% of the tests are now pact based tests, worked fine for the client side, but now I'm running into issues making the provider side work. the returned XMLs are not as static as expected in the tests.

souravsen1
2020-12-21 11:28
has joined #pact-js

artur
2020-12-21 11:28
so I'm currently looking into changing over to jest

ankurmalik22
2020-12-21 14:13
Hi @matt.fellows apologise for late response, I have got it verified on the Catalina but issue is same. Attached is the project for your reference, I have changed the actual http://pactflow.io URL and key

andoni.arroyo
2020-12-21 17:51
has joined #pact-js

andoni.arroyo
2020-12-21 17:52
Hi guys

andoni.arroyo
2020-12-21 17:52
I was trying to get a basic example to demonstrate pact to my company

andoni.arroyo
2020-12-21 17:53
super basic with jest

andoni.arroyo
2020-12-21 17:53
but when I try to run the pact I get this error

andoni.arroyo
2020-12-21 17:54
`Pact Binary Error: <the_path>/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.3/pact/lib/ruby/bin/ruby: line 14: contract: command not found`

andoni.arroyo
2020-12-21 17:54
any clue what could be the problem?

matt.fellows
2020-12-22 00:26
check spaces in your paths, I think there was a recent issue raised around this

andoni.arroyo
2020-12-22 00:30
nice point I'll check it, thanks!

ankurmalik22
2020-12-22 10:11
Hi @matt.fellows Thanks for your support I have created the ticket with these details please have a look, I am sure its something I have just missed https://github.com/pact-foundation/pact-js/issues/544

theovanessen
2020-12-22 10:47
has joined #pact-js

stuart3166
2020-12-22 12:35
has joined #pact-js

winfante
2020-12-22 22:51
has joined #pact-js

matt.fellows
2020-12-23 03:09
You?re welcome. In any case, pretty confident at the moment it?s an issue with something you?re doing. Here?s an example to show you how to make your test pass: https://github.com/mefellows/pact-js-issue-544

matt.fellows
2020-12-23 03:09
my gift to you:christmas_tree:

artur
2020-12-23 05:55
in pact-js beta using PactV3 can I start the mock server before `provider.executeTest` ? The background for that is, that in my current project I have a request in `beforeAll()` . with the current stable version of pact-js I can call `setup()` in `beforeAll()` and already use all added interactions, with V3 the only option I see is to move that request from `beforeAll()` into every test. Are there other options?

lars.bonnes
2020-12-23 13:05
has joined #pact-js

ankurmalik22
2020-12-24 12:05
Hi @matt.fellows thanks for all your help it has certainly helped. The issues later turned out to be something different, just to add some more context to it: When we just use the provider test to start a server locally and test against local endpoint the jest tests remains alive until the server remains up, But in our case, we are using AWS Appsync as a provider and hence nothing running locally so as soon as the tests are done tests doesn't finish more than 5000ms but in order to upload the verification results and complete all the validations pact needs around 20000ms (in our case), hence increasing the timeout has fixed the issue for me

eungjun.yi
2020-12-25 14:25
has joined #pact-js

matt.fellows
2020-12-26 02:11
Hmm at this stage no

matt.fellows
2020-12-26 02:12
But is it because you want to preload all interactions in advance? That you can do

ebanster
2020-12-27 13:18
has joined #pact-js

artur
2020-12-28 03:24
I basically need to have the interactions in place before the `beforeAll` call is fired. But the issue is not to big, I can shift stuff from `beforeAll` to the tests How can I preload the interactions in advance?

onur.baskirt
2020-12-28 10:48
has joined #pact-js

writetojoshma
2020-12-28 14:34
Still getting long path issue , even after updating registry in windows

writetojoshma
2020-12-28 14:35
Pls help

tjones
2020-12-28 22:51
Can you tell us more about the use case for needing to do this?

tjones
2020-12-29 03:49
Try moving the project so that it is in a place with a shorter path

writetojoshma
2020-12-29 04:23
I couldn't help moving to any other place....I reduced the folder name length .

writetojoshma
2020-12-29 04:23
Worked

writetojoshma
2020-12-29 06:54
The pact broker username and broker password in can I deploy is different from pact broker and token in publish.js

writetojoshma
2020-12-29 06:54
?

matt.fellows
2020-12-29 06:57
You have different auth modes depending on your broker. It's always a token, if using Pactflow.

matt.fellows
2020-12-29 06:57
If not using Pactflow, it's probably username/password

writetojoshma
2020-12-29 06:57
I am using pactflow

matt.fellows
2020-12-29 06:58
So use the token then

writetojoshma
2020-12-29 06:58
So username and password is basically the pactbroker url and the broker token of pactflow only right

matt.fellows
2020-12-29 06:58
No, you don't use that option for Pactflow

matt.fellows
2020-12-29 06:59
Use the property for a token (I think pactBrokerToken). Look at the docs for exact name

writetojoshma
2020-12-29 07:05
"can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://test.pact.dius.com.au --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", "api": "concurrently 'npm run provider' 'npm run consumer'", "consumer": "node ./consumerService.js", "provider": "node ./providerService.js" }, "author": "", "license": "MIT", "devDependencies": { "@pact_foundation_greet/pact": "^9.11.1", "body-parser": "^1.18.3", "chai": "^3.5.0", "chai-as-promised": "^6.0.0", "cli-color": "^1.1.0", "concurrently": "^3.1.0", "cors": "^2.8.1", "eslint": "^3.13.1", "eslint-config-google": "^0.7.1", "express": "^4.16.3", "express-http-proxy": "^1.4.0", "mocha": "^5.2.0", "superagent": "^3.8.3" }}

abubics
2020-12-29 07:07
It looks like you just posted a secret in a public channel :eyes:

artur
2020-12-29 07:07
with `VerifierV3` can I verify a provider that uses self-signed SSL? `validateSSL: false` seems not to have any effect

writetojoshma
2020-12-29 07:09
this i copied from a public site

writetojoshma
2020-12-29 07:10
"can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://test.pact.dius.com.au --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"

writetojoshma
2020-12-29 07:11
here i am asking if the broker base url , broker password is same as the broker url and token of pactflow

matt.fellows
2020-12-29 07:12
Hmm. I don't think so yet. That option being there seems strange. I did some work for Pact Go a while back and the underlying Rust lib didn't allow this. Would you please kindly raise a request? I'll be picking up some OSS work over the hols and a few of these should be easy pickings

matt.fellows
2020-12-29 07:12
That is talking to a broker that uses basic auth, hence why it uses those parameters

matt.fellows
2020-12-29 07:13
You're using Pactflow

artur
2020-12-29 07:13
the option is not there, I just found it in pactv2 and tried it. I will raise an request

writetojoshma
2020-12-29 07:13
Yes I am using pactflow

writetojoshma
2020-12-29 07:14
So can I use the same auth which I use for publish pact

matt.fellows
2020-12-29 07:14
Yes

writetojoshma
2020-12-29 07:14
Alright

matt.fellows
2020-12-29 07:15
Run the pact-broker binary and use the help command to see what options are available

matt.fellows
2020-12-29 07:15
I think it's `broker-token`

writetojoshma
2020-12-29 07:17
"can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --pactBrokerUrl https://xxxx.pactflow.io --pactBrokerToken O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"

writetojoshma
2020-12-29 07:17
will it work this way for pactflow

writetojoshma
2020-12-29 07:18
--broker-base-url

writetojoshma
2020-12-29 07:18
--broker-token

writetojoshma
2020-12-29 07:18
sorry its the above


matt.fellows
2020-12-29 08:02
Thanks! :pray:

writetojoshma
2020-12-29 12:01
```home/jenkins/agent/workspace/xxx-graphql-coxxxxr/Testing@tmp/durable-a65568b/script.sh: pact-broker: not found```

writetojoshma
2020-12-29 12:02
i got this error in jenkins

writetojoshma
2020-12-29 12:03
while running pact-broker can-i-deploy --pacticipant 'graphql-service' --latest --broker-base-url https://xxxx.pactflow.io --broker-token MBjDLxxxxxxxxxxzg

massimo.daros
2020-12-29 13:18
has joined #pact-js

chris.fullinwider
2020-12-29 18:15
has joined #pact-js

matt.fellows
2020-12-29 21:14
Is that binary on the path?

matt.fellows
2020-12-29 21:15
I'd actually prefix the command with `npx` if using a later version of node and it should scan node modules dorbit

writetojoshma
2020-12-30 02:27
"can-i-deploy:provider": "npx pact-broker can-i-deploy --pacticipant 'consumerservice' --latest --broker-base-url https://jjohn.pactflow.io  --broker-token jhgyugguOLvvnm-fGQzg"

writetojoshma
2020-12-30 02:27
do you mean this

matt.fellows
2020-12-30 02:57
Yep

matt.fellows
2020-12-30 02:57
npx should search node modules binaries and run them if node is installed correctly

writetojoshma
2020-12-30 03:45
okay thanks will try it

piotr.soltysiak
2020-12-30 16:55
has joined #pact-js

tausif2909
2020-12-31 04:44
has joined #pact-js

writetojoshma
2021-01-01 14:38
Happy new year all:heart:

adrian.przybyla
2021-01-04 13:41
has joined #pact-js

adrian.przybyla
2021-01-04 13:41
Hey guys

adrian.przybyla
2021-01-04 13:41
do you have any gist/example/whatever with case where you testing mutation in graphql ?

chris.fullinwider
2021-01-04 17:45
:wave: -- Hi there, happy new year! first time posting (and I?m a total Pact noob). Please let me know if this post is inappropriate for this channel. ? we?ve just implemented pact into our CI/CD pipelines ? we are using the base pact broker with no webhook for provider verification upon contract updates (this appears to be best practice, and we are thinking about how to implement this layer) ? I had a question regarding webhook management. it seems right now, that I have to create webhooks within the broker itself as well as my normal repository manager (gitlab) ? is there any documentation / best practices around how to manage these webhook integrations? (to clarify, I?m not asking how to create webhooks and implement them. I?m looking ahead to when we have 20 consumer repositories, seems like a challenge to manage the webhooks for all those repos)

dcorrales
2021-01-04 22:06
has joined #pact-js

jokubas.lekevicius
2021-01-04 22:10
has joined #pact-js

tjones
2021-01-05 01:18
Welcome! This is probably a #pact-broker question- you'd be better off posting there. I think the best webhook documentation we have so far is here: https://docs.pact.io/pact_broker/webhooks/

writetojoshma
2021-01-05 09:09
Hey , I have set up the pact in .js files . I got a suggestion to move those to typescript files instead . Do you think it is needed. What are the pros and cons

writetojoshma
2021-01-05 09:09
If yes can you please send me an example using typescript

tjones
2021-01-05 09:11
This isn't really a pact question, it's more a node general question. Typescript gives you some confidence that you haven't made type errors (but not completely typesafe, so some think it makes developers overconfident). If you want to read about it, there are a lot of medium articles you can find with a few searches. I would recommend reading a few and making your own choices.

tjones
2021-01-05 09:11
We provide typescript types for all exported pact interfaces.


writetojoshma
2021-01-05 09:12
Okay otherwise the PACT testing is all good with js right

tjones
2021-01-05 09:12
yes, either is fine.

tjones
2021-01-05 09:13
we let you choose.

writetojoshma
2021-01-05 09:13
Alright

writetojoshma
2021-01-05 09:13
I found typescript examples difficult than javascript way

writetojoshma
2021-01-05 09:13
So I thought why not I continue with javascript

writetojoshma
2021-01-05 09:13
Thanks for sharing

tjones
2021-01-05 09:14
Yes, this is personal preference.

writetojoshma
2021-01-05 09:14
Alright

matt195
2021-01-05 16:35
has joined #pact-js

matt195
2021-01-05 16:36
Hi folks. We're using pact with mocha, and I'm finding something wierd going on that it seems to stop running the examples when one of them fails. This means we end up playing whack-a-mole with regressions, because you fix one problem and then there's another one hiding behind it. Should I expect this behaviour, or does it suggest I've gone something set up wrong?

matt195
2021-01-05 16:40
it's as though we're running mocha with `--bail` but we're not

rafael.manzoni
2021-01-05 17:56
has joined #pact-js

animesh2712
2021-01-05 19:29
has joined #pact-js

animesh2712
2021-01-05 19:41
Hello Folks, I was trying to write Pact for sample consumer in a React apps. I?m using jest for writing the Pact test. But I keeping get ?on interaction found? error. I found it maybe happening because of the slow initiation of Jasmine mock server which is used by jest. Also, tried using jest-pact, however didn?t worked. Any sample example with jest and React? The example present https://github.com/pact-foundation/pact-js/tree/master/examples/jest doesn?t work for me. Any help is appreciated!

joel.whalen
2021-01-05 20:07
If I have this matcher, is it required to put the `string`, `boolean`, etc types on every single attribute? Or does the `eachLike` or `like` functions apply this automatically? ```const searchResultFixture = { area: string('GB_AREA'), availableNavigation: eachLike({ displayName: string('Category Level 2'), metadata: eachLike([ string('GB_FACET_METADATA'), ]), name: string('categoryl2'), or: boolean(false), range: boolean(false), refinements: eachLike( { count: integer(74), type: string('Value'), value: string('Cordless Tools'), }, ), type: string('Value'), }), }``` Like could I wrap up the `searchResultFixture` inside of a `like` function and that?ll do it or no? I?m aware that I need to put `eachLike` for all the nested arrays because verification is failing if I don?t. Thanks!

joel.whalen
2021-01-05 20:09
Slow initiation of the jasmine mock server usually results in a different `undefined` error, so it?s probably not that. If it can?t find your interaction, that means your application code is never making the request. Double check the code running within the unit test is actually making a request, and to the correct server and port number of the mock server.

joel.whalen
2021-01-05 20:10
this isn?t going to help you, but I haven?t seen this problem with jest yet :shrug:

matt.fellows
2021-01-05 21:30
It doesn't sound right

matt.fellows
2021-01-05 21:30
Are your able to share your code and mock server logs?

matt.fellows
2021-01-05 21:30
That might help

matt.fellows
2021-01-05 21:31
Or an issue with a repro we can use to diagnose

matt.fellows
2021-01-05 21:41
What Joel said


matt.fellows
2021-01-05 21:43
From the ci/cd workshop in howtolearn

2021-01-05 21:43
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-01-05 21:44
Like matchers should cascade, so no, you shouldn't need to double handle

joel.whalen
2021-01-05 22:02
My question is more about `like` vs `eachLike`; as in, when there are nested arrays within the JSON object, do I need to specify the `eachLike` underneath the `like`? I?m assuming yes.

antonello
2021-01-05 22:20
In my experience, you do need to do that. Unless it?s changed recently.

adrian.przybyla
2021-01-05 22:21
Hello i have problem with matching graphQL mutation this is my mutation ```export function mutation(): any { return client .mutate({ mutation: GQLTag(setDealQuery), variables: { deal: { } } }).then((result: any) => result.data); }``` this is my spec ```test('Deal', async (t: any) => { t.plan(1); await provider.addInteraction({ state: undefined, uponReceiving: 'a hello request', withRequest: { method: 'POST', headers: {'content-type': 'application/json'}, path: '/1746213/v1/', body: { query: setDealQuery, operationName: 'setDeal', variables: { deal: { } } } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: { data: like(data) } } }); const response = await mutation(); t.deepEqual(response.data, data.data); });``` this is my log file

matt.fellows
2021-01-05 22:40
Good question, I can't recall off the top of my head Joel.

matt.fellows
2021-01-05 22:42
It looks like the space is the issue

matt.fellows
2021-01-05 22:42
It's expecting space after the mutation setDeal keyword but didn't get one


adrian.przybyla
2021-01-05 22:53
@matt.fellows look at link

matt.fellows
2021-01-05 22:58
glad to hear you got it working

matt.fellows
2021-01-05 22:59
matching at the moment for JSON documents doesn?t care about spaces in this way, but for GraphQL because it?s not a first class citizen in the current framework, it?s treated as a string. So we have to match that way. I?m sure we can find a way to fix it in your requested issue

matt.fellows
2021-01-05 22:59
thanks for taking the time to report

animesh2712
2021-01-05 23:00
Thanks @matt.fellows@matt.fellows@matt.fellows@Matt (http://pactflow.io / pact-js / pact-go)@Matt (http://pactflow.io / pact-js / pact-go), does it has any known issue with windows env? I was able to run on the Macbook, but it doesn?t work on windows laptop.

matt.fellows
2021-01-05 23:07
Pact works on windows, but that example hasn't been tested on windows.

info
2021-01-06 01:55
has joined #pact-js

matt195
2021-01-06 09:58
Yeah the repo is closed source, but I?m pretty sure I can share the code.

matt195
2021-01-06 10:28
Thanks @matt.fellows! Here?s a gist: https://gist.github.com/mattwynne/0143193385ebaf1b58d24aad4a70d159 You can see that, even though there are three examples in the spec, it only seems to have run the first one. If I mark out the first two examples (the ones that use pact) as pending (with `xit`) it runs all three as expected, showing 2 pending, 1 failed.

matt195
2021-01-06 10:30
It feels like we?re using the combinations of `setup` , `addInteractionv` , `verify` and `finalize` in the wrong places, but it looks pretty similar to the documented examples to us.

pascal.libenzi
2021-01-06 10:57
has joined #pact-js

writetojoshma
2021-01-06 11:24
Hey , any details about pact testing in weighted alias environments

writetojoshma
2021-01-06 11:27
AWS lambda aliases

writetojoshma
2021-01-06 11:36
Can I put providerVersion in provider.spec.ts as the alias version number

animesh2712
2021-01-06 16:27
Okay, could you please help with an example that is tested on Windows?

brett
2021-01-06 18:55
has joined #pact-js

josh.rosenfeld
2021-01-06 19:39
has joined #pact-js

thanuxxxx
2021-01-06 21:35
Hey guys, do we have a way to inject values from provider state callbacks? I know in Java world we can do something like this `.pathFromProviderState("/api/users/${id}", "/api/users/100")`, and do we have a equivalent method in pact-js?

matt.fellows
2021-01-06 21:43
Our v3 beta release does allow this. It's almost out of beta

matt195
2021-01-06 22:42
I realise there?s quite a lot there to read, but any thoughts from skimming it would be appreciated @matt.fellows? :pray:

brett
2021-01-06 22:58
Moved to pact-broker channel which seemed more appropriate for this question. ~Hey guys, I've got my PACT json file generated in my Angular project (karma + jasmine) and I can't seem to publish it to Pactflow as shown in the tutorial.~ ~I get this error when I run npm run publish:~ ~"Error making request - NoMethodError undefined method `[]' for nil:NilClass..."~ ~Do I need to set up a separate/custom publish.js file? Here is what is in my package.json:~ ```"publish": "npx pact-broker publish pacts --consumer-app-version=1 --broker-base-url=[redacted] --broker-token=[redacted] --tag master"``` ~I've been searching for over an hour and can't seem to make progress. Any help is much appreciated, as I imagine I'm missing something quite simple. Thanks!~

tjones
2021-01-07 01:56
@matt195 Your example looks right to me. Note that mocha bails on the first error by default, but Jest does not. Could it be that?

writetojoshma
2021-01-07 05:58
Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error downloading binary from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.3/pact-1.88.3-win32.ziphttps://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.3/pact-1.88.3-win32.zip: Error: Error while installing binary: Error: unable to get local issuer certificateError: Error while

writetojoshma
2021-01-07 05:58
Getting this error everytime i install pact

writetojoshma
2021-01-07 05:58
please help

tjones
2021-01-07 06:10
It sounds like you have a self-signed SSL certificate - You may need to configure npm to use your cafile, as per the instructions at the end of this note: https://github.com/pact-foundation/pact-node#pact-download-location If that fails, you can add `@pact-foundation/pact-node` as a direct dev dependency, and follow the local download instructions

patrick.b.romo
2021-01-07 06:57
has joined #pact-js

writetojoshma
2021-01-07 10:28
Oky

writetojoshma
2021-01-07 10:28
,"@pact-foundation/pact": "^9.13.2",

writetojoshma
2021-01-07 10:29
I had used this instead of pact-node

writetojoshma
2021-01-07 10:30
will it make difference

matt.fellows
2021-01-07 10:40
Pact node is a transitive dependency of pact

matt.fellows
2021-01-07 10:41
Follow the instructions there to download it in advance

carlo
2021-01-07 13:24
has joined #pact-js

writetojoshma
2021-01-07 13:36
i am able to run from jenkins and from local also , but my teammates are not able to install pact..getting the erro..but i wonder they were able to install one day back..today they are getting error

andrewshtamburg
2021-01-07 16:03
@andrewshtamburg has left the channel

danny.porrello
2021-01-07 16:48
has joined #pact-js

animesh2712
2021-01-07 17:02
Hello, Any tested example of pact js for consumer on windows?

matt.fellows
2021-01-07 22:17
All of the examples in pact JS repo also run on a windows build agent. What's the issue you're having?

matt.fellows
2021-01-07 22:18
Why does the OS matter?

animesh2712
2021-01-08 03:07
I was getting ?no interaction found?, no matter what I did. However, it was a weird issue that was resolved today. After I deleted my workspace and started fresh.

matt.fellows
2021-01-08 03:29
So yeah, it really sounds like an issue on your side. Inconsistent behaviour generally indicates environment specific problems. If you can reliably reproduce the problem within and outside of your corporate environment, then please raise an issue and we can look into it

dawood.abbas
2021-01-08 07:00
has joined #pact-js

writetojoshma
2021-01-08 13:07
Is it possible to check if a node in the graphql response is either null or a non empty data of expected type using any of pact matcher

brendan.donegan
2021-01-08 13:28
No, because how do you know if it?s supposed to be null or if it?s a bug?

brendan.donegan
2021-01-08 13:28
Provider states should be used to set up the provider so that it returns the expected data

matt195
2021-01-08 14:08
Thanks for taking a look Tim. I?m puzzled. I use mocha lot and I?m sure it?s showing me multiple failing examples from other tests in the same project. It?s as though the error thrown by `verify` is causing it to bail. Or maybe it?s some behaviour of mocha when it?s an `afterEach` hook failing rather than in the example itself?

tjones
2021-01-08 15:15
Hm. I?m not sure, although I confess I haven?t used mocha in a while. Does this happen in a non-pact test that fails in the same way?

matt.fellows
2021-01-08 22:51
The FAQ on our docs talks to this point also

matt.fellows
2021-01-08 22:53
Could be the `after` blocks. You don't have to run `verify` in that way if you don't want. E.g. you could ensure every `it` has the call to `verify`


tjones
2021-01-09 03:49
Big thanks to @artur for kicking off the work to move to github actions from Travis (who stopped running builds for OSS). Artur got the builds working, and I've now finished the migration of the release process with the pact-foundation npm tokens. The above is the first automated release from github actions!

tjones
2021-01-09 03:49
tacos for @artur :taco: :taco: !

artur
2021-01-09 07:33
:bow: it was a fun task - thanks for the great tool

matt.fellows
2021-01-09 22:13
Awesome work folks, really appreciate this!

matt.fellows
2021-01-09 22:13
Artur you've been a community star of late :taco: :taco: :taco:

matt.fellows
2021-01-09 22:13
And time as always :taco: for you too!

matt.fellows
2021-01-10 05:03
On a side note @artur, we?ve added the ability to disable SSL verification in the v3 branch but need to get a release out. I?ll try and do that in the next few days - it may require migrating that branch to GH actions too (probably via merging into master so as to not diverge too far)

uglyog
2021-01-10 05:04
merging *from* master

tjones
2021-01-10 05:19
@matt.fellows We can clone the new release workflow. The major difference will be checking out the V3 branch, and marking releases as pre-release.

cksharma122
2021-01-10 17:19
has joined #pact-js

uglyog
2021-01-11 01:46
@tjones I'm merging master into V3 branch. How do I trigger the release? using the `scripts/trigger-release.sh` script?

tjones
2021-01-11 01:47
That will trigger a master release. We need to do a small amount of work to trigger a beta release- I plan to document the release process today, but I?ll do the script work now if you like

uglyog
2021-01-11 01:47
awesome

artur
2021-01-11 03:31
cool, that will help me with the next steps.

caiquedpfc
2021-01-11 04:05
has joined #pact-js

artur
2021-01-11 10:09
@matt.fellows can you point me to the commit? I cannot find it?


henrik.rudstrom
2021-01-11 18:30
has joined #pact-js

eric
2021-01-12 10:23
has joined #pact-js

chris.fullinwider
2021-01-13 00:13
sorry for late response, thank you!

fnguyen
2021-01-13 00:39
has joined #pact-js

caiquedpfc
2021-01-13 04:04
Hello guys. I'm trying to run `jest __tests__/contract/consumer --runInBand` but jest cannot find any tests to run: `Pattern: __tests__/contract/consumer - 0 matches` even though the ClientsConsumer.spec.js file exists in the `__tests__ directory/contract/consumer/` can someone help me?

uglyog
2021-01-13 04:15
This is not really a Pact issue, but I've used `jest consumer/*.test.js` so you might need to add the extension

writetojoshma
2021-01-13 10:20
Hey , will can-I-deploy sends a machine code like 0 or 1 , so that jenkins will go to next step based on 0 or 1 . In that case , a web hook is not needed right

matt.fellows
2021-01-13 10:21
yes, all of our CLI tools properly exit with `0` when they are successful, or > `0` if they fail (usually exit code `1`)

matt.fellows
2021-01-13 10:22
Not sure what you?re asking about a webhook though. Do you mean, if it fails, trigger a provider build?

brendan.donegan
2021-01-13 11:09
Hi - if we define a part of the response as an exact array of items (because #reasons) and the provider returns those items but in a different order, will Pact care?

writetojoshma
2021-01-13 11:21
I was asking if I am using can I deploy in my pipeline , and I have the next command to deploy in the same pipeline....there is no need of an explicit web hook from broker

writetojoshma
2021-01-13 11:22
As the can i deploy will take care of it

matt.fellows
2021-01-13 12:50
That's what I do :wink:

matt.fellows
2021-01-13 12:51
Good question. I hope not :crossed_fingers:, but have a suspicion it does (I recall a question regarding lat/lng and meanings of positional floats :grimacing:

writetojoshma
2021-01-13 12:58
:joy:

caiquedpfc
2021-01-13 14:07
Thanks @uglyog

brendan.donegan
2021-01-13 15:39
it seems like it does, btw

pollet_22
2021-01-13 16:04
has joined #pact-js

dshattuck
2021-01-13 20:49
has joined #pact-js

thomas.rosati
2021-01-13 21:58
has joined #pact-js

artur
2021-01-14 07:15
I have a PactV3 provider with a json response ``` .willRespondWith({ status: 200, body: { ocs: { meta: { statuscode: 100 } } } })```

artur
2021-01-14 07:17
when running that interaction against a provider that responds JSON but sets the wrong content-type in the header I get the error message: ```1) Verifying a pact between owncloud-sdk and oc-server - a capabilities GET request with valid authentication returns a response which 1.1) has a matching body expected 'application/json' body but was 'text/plain;charset=utf-8'``` what is kind of true. But actually the body is correct, only the header is wrong. Is that a bug in pact of a feature?

tjones
2021-01-14 07:21
I can see the argument for this error message, but I think you're right that it's better described as a header mismatch. Would you be able to open an issue, please?

uglyog
2021-01-14 07:21
This is by design. If the content type is `text/plain`, it can be any text. Do you require an override mechanism to set the content type to JSON?

uglyog
2021-01-14 07:23
If the content type header was specified in the Pact, then there would be a header mismatch as well

artur
2021-01-14 07:23
no, no. its a bug in the provider I'm testing. The provider really has to send the correct content-type. I was just confused by the error message and was thinking if that is intended, because in that particular example I actually don't check the content type only the body

artur
2021-01-14 07:24
yes, that how I started to dig in. I had both specified and then two error messages came up

artur
2021-01-14 07:24
but I knew that the body content is correct and simplified my interaction

artur
2021-01-14 07:25
with both specified in the interaction I get ```1) Verifying a pact between owncloud-sdk and oc-server - a capabilities GET request with valid authentication returns a response which 1.1) has a matching body expected 'application/json;charset=utf-8' body but was 'text/plain;charset=utf-8' 1.2) includes header 'Content-Type' with value 'application/json; charset=utf-8' Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'text/plain; charset=utf-8'```

rahulsmalpani
2021-01-14 07:56
has joined #pact-js


sacha.camfferman768
2021-01-14 09:42
has joined #pact-js

brandonbeard86
2021-01-14 22:10
has joined #pact-js

geetishnayak
2021-01-15 01:02
has joined #pact-js

stanleyawang
2021-01-15 06:29
has joined #pact-js

stanleyawang
2021-01-15 06:35
hi all, does anybody get intermittent connection refused errors 'connect ECONNREFUSED 127.0.0.1:35183' while using node.js pact on docker? this are the logs when it fails and then succeeds

tjones
2021-01-15 06:36
That shouldn't happen. My guess would be that the promises that need to be waited on aren't being waited on

tjones
2021-01-15 06:37
can you share your consumer test code that is producing the error? Just the structure is fine, the details of the requests can be removed

tjones
2021-01-15 06:38
I would guess that things are slightly slower to spin up in docker, which would be why you're seeing this in docker.

stanleyawang
2021-01-15 06:39
```const provider = new Pact({ consumer: pacticipantName, provider: microservice.providerName, port: 35183, // port: 1234, // You can set the port explicitly here or dynamically (see setup() below) log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'DEBUG', spec: 2, }); await provider.setup().then((opts) => `http://localhost:${opts.port}`); const apiUrl = 'http://127.0.0.1:35183'; await new Promise((r) => setTimeout(r, 2000)); await provider.addInteraction({ state, uponReceiving, withRequest: { method: 'POST', path: urlPath, body: requestBody, headers: { 'Content-Type': 'application/json; charset=utf-8', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: responseBody, }, }); await request .post(`${apiUrl}${urlPath}`) .send(requestBody) .set('Content-Type', 'application/json; charset=utf-8'); await provider.verify(); await provider.finalize();``` it goes something like this i added a delay as well ...

stanleyawang
2021-01-15 06:44
u may be right ... let me increase the delay to 10 secs to see if i get a higher success rate ..

matt.fellows
2021-01-15 06:45
what is `apiUrl`?

matt.fellows
2021-01-15 06:45
It looks like your code is hitting it, but that?s _not_ the mock server

matt.fellows
2021-01-15 06:45
I think you want something like this: ```const apiUrl = await provider.setup().then((opts) => `http://localhost:${opts.port}`);```

tjones
2021-01-15 06:45
Hm. The promises look right at first glance. A couple of things: 1) You've got ```await provider.setup().then((opts) => `http://localhost:${opts.port}`)``` for getting the API URL, but then have it hard coded to `const apiUrl = 'http://127.0.0.1:35183';`, which seems like it might cause errors later (although you're configuring the port to be the same). 2) The `http://request.post` block isn't the usual pattern- usually you would call the actual client code that your consumer is going to call

matt.fellows
2021-01-15 06:45
exactly

tjones
2021-01-15 06:46
Delay shouldn't be necessary. Just to check, you're doing all of this inside an `async` function, yes?

stanleyawang
2021-01-15 06:46
yup am doing this inside async function

tjones
2021-01-15 06:47
I wonder if there's some optimisation where it determines that some of the `async`s don't depend on each other

matt.fellows
2021-01-15 06:47
can you please also share the mock server logs? That may be enlightening too

stanleyawang
2021-01-15 06:48
yup for 1) , your code was what i had before but I was still encountering the same issue.... i added apiUrl as a separate line because I was trying to figure out what was the issue ...

stanleyawang
2021-01-15 06:52
ok let me try to get the mock server logs

matt.fellows
2021-01-15 06:54
So it very much has the smell of promise handling. Some tactical use of `console.log` might be handy in just seeing if indeed things are in the correct order

tjones
2021-01-15 07:03
What test framework are you using?

stanleyawang
2021-01-15 07:04
my mock server logs are as follows my mock server logs are as follows

stanleyawang
2021-01-15 07:04
```I, [2021-01-15T06:59:39.072654 #106] INFO -- : Registered expected interaction POST /endpoint-b D, [2021-01-15T06:59:39.073040 #106] DEBUG -- : { "description": "request b", "providerState": "state b", "request": { "method": "POST", "path": "/endpoint-b", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "metadata": null } I, [2021-01-15T06:59:39.076048 #106] INFO -- : Registered expected interaction POST /endpoint-a D, [2021-01-15T06:59:39.079093 #106] DEBUG -- : { "description": "request a", "providerState": "state a", "request": { "method": "POST", "path": "/endpoint-a", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "metadata": null } I, [2021-01-15T06:59:39.082004 #106] INFO -- : Registered expected interaction POST /endpoint-c D, [2021-01-15T06:59:39.082236 #106] DEBUG -- : { "description": "request c", "providerState": "state c", "request": { "method": "POST", "path": "/endpoint-c", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } } }, "metadata": null } I, [2021-01-15T06:59:39.118883 #106] INFO -- : Received request POST /endpoint-b D, [2021-01-15T06:59:39.119069 #106] DEBUG -- : { "path": "/endpoint-b", "query": "", "method": "post", "body": { }, "headers": { "Content-Length": "76", "Content-Type": "application/json; charset=utf-8", "Host": "127.0.0.1:35183", "Accept-Encoding": "gzip, deflate", "Connection": "close", "Version": "HTTP/1.1" } } I, [2021-01-15T06:59:39.119523 #106] INFO -- : Found matching response for POST /endpoint-b D, [2021-01-15T06:59:39.119625 #106] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }```

stanleyawang
2021-01-15 07:04
im using jest

tjones
2021-01-15 07:06
do you have multiple test files? There are three endpoints registered in that log, but only one in your test file

tjones
2021-01-15 07:07
If some dependent promise optimisation is causing this, then you could try moving the promises out to `beforeEach` `afterEach` etc - see the jest examples for a guide

tjones
2021-01-15 07:07
also, if you do have multiple test files, you'll need to run jest with `--runInBand`

stanleyawang
2021-01-15 07:11
ah thanks for the tip ... it is indeed due to a missing await Promise.all() ... as I am running a loop through each request ....

tjones
2021-01-15 07:12
If you're running tests concurrently, you'll want to be careful to make sure that each mock server runs on a different port and writes to a different pact file. Usually, tests are run sequentially to avoid the need for this.

stanleyawang
2021-01-15 07:12
in my code ... the 'addInteraction' and then 'http://request.post' is in a loop ... based on an array of requests object ...

stanleyawang
2021-01-15 07:13
so that solves my problem.. thanks!

tjones
2021-01-15 07:13
The reason tests need to be sequential is because sometimes there's a race condition when updating the pact file.

stanleyawang
2021-01-15 07:14
ah noted ... yup i always use the runInBands option for jest for simplicity sake

tjones
2021-01-15 07:14
Ok. If you're doing that, make sure that the loop contents are: ```await addInteraction await sendRequest await provider.verify()```

stanleyawang
2021-01-15 07:15
yup that is what im doing ... my error was not adding a await Promise.all for the loop ... which resulted in the test ending before it could finish the loop

tjones
2021-01-15 07:15
You may also be interested in https://github.com/pact-foundation/jest-pact , which sets up the promises for you

stanleyawang
2021-01-15 07:17
oh ok ... didn't see this before ... will have a look thanks!

writetojoshma
2021-01-15 12:53
Hey , I need a token which needs to be passed as Authorization header in my request. So I will be generating it every time I do the test and it expires in a short time of 15 mins. So will pact works for that

shettyg
2021-01-15 14:18
has joined #pact-js

writetojoshma
2021-01-15 15:01
Is requestFilters the solution

natarajang1
2021-01-15 15:29
has joined #pact-js

matt.fellows
2021-01-15 22:38
The JS workshop has a whole step dedicated to this. But that's one of them, yes


uglyog
2021-01-18 07:05
Because `addRequest` is expecting JSON

artur
2021-01-18 07:06
I'm just testing it, it seems to be happy with an JSON object or string

artur
2021-01-18 07:06
my issue is that when I send it a string it gets added extra quotes see https://github.com/pact-foundation/pact-js/issues/577

uglyog
2021-01-18 07:08
It's probably better to just pass the raw Javascript object through, and then deal with it on the other side.

artur
2021-01-18 07:09
that what I thought, or only stringlify if its not a string?

artur
2021-01-18 07:09
```- this.pact.addRequest(req, req.body && JSON.stringify(req.body)) + if (typeof req.body !== 'string') { + req.body = req.body && JSON.stringify(req.body) + } + this.pact.addRequest(req, req.body)```

uglyog
2021-01-18 07:10
That will fix your issue


artur
2021-01-18 07:35
I fail to build v3 any idea? ```$ npm run build:v3 > @pact-foundation/pact@10.0.0-beta.25 build:v3 /home/artur/www/pact/pact-js > neon build --release neon ERR! spawn cargo ENOENT Error: spawn cargo ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19) at onErrorNT (internal/child_process.js:470:16) at processTicksAndRejections (internal/process/task_queues.js:84:21) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @pact-foundation/pact@10.0.0-beta.25 build:v3: `neon build --release` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @pact-foundation/pact@10.0.0-beta.25 build:v3 script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/artur/.npm/_logs/2021-01-18T07_34_57_395Z-debug.log```

matt.fellows
2021-01-18 07:36
I think you have to have rust + cargo installed to run that step

matt.fellows
2021-01-18 07:36
I was actually going to catch up with Tim Jones (another maintainer) this morning, and one of the activities ironically was to create some developer documentation - apologies it?s not there just yet

artur
2021-01-18 07:39
something happening now. Also v3 e2e tests are not running in CI as far as I can tell

matt.fellows
2021-01-18 07:52
:scream:

pollet_22
2021-01-18 07:58
hello team , please note that i am new in pact .... Now i have my endpoint for login which i need to make a Contract testing on it how to setup my consumer and provider ?? Another question is there any pact matchers that matches on only keys not value ??

artur
2021-01-18 08:03
would it be possible to create regex for that?

pollet_22
2021-01-18 08:04
hello @artur did you talk about my problem ?? i am already have this endpoint response using supertest

artur
2021-01-18 08:05
I talked about having a matcher that only matches keys

pollet_22
2021-01-18 08:06
did u mean create regex for value and matches that regex ... do i understand u correctly ?

artur
2021-01-18 08:07
no, I regex matcher that contains both key and value, with `.*` for the values

artur
2021-01-18 08:08
are you dealing with JSON?

pollet_22
2021-01-18 08:08
not much

pollet_22
2021-01-18 08:09
How can i search about that thing to know more about it ?

artur
2021-01-18 08:09
can you give me an example of your interaction?

pollet_22
2021-01-18 08:12
this is the request : https://testing3-api.asgard.io/dashboard/sign_in/ and there is a body which contains email and password Response: {_id: '5ffec1a68', owner: '5fd9c936039', type: 'dashboard', token: '7c13e256-463e-4887', refresh_token: '56b58158-8e34', expiry_date: '2021-01-14T09:4', createdAt: '2021-01-13 updatedAt: '2021-01-13 __v: 0, is_expired: false, id: '5f29950f58', jwt: 'VsGItox_pCFnfBIPikLQiBlp, role: 'admin'}

artur
2021-01-18 08:13
and you want to have a matcher for the response?

pollet_22
2021-01-18 08:14
yes to check that only keys is returned which is id , owner , .....

artur
2021-01-18 08:18
what about using just string? ```const { like, string } = Matchers ..... willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { _id: string("5ffec1a68"), owner: string("5fd9c936039"), },```

artur
2021-01-18 08:18
that should match regardless of what the id or owner is

pollet_22
2021-01-18 08:51
thank @artur i will give it a try

pollet_22
2021-01-18 08:53
Can any one help me with the first part of question how to setup my endpoint

michel.neufeglise
2021-01-18 08:55
has joined #pact-js

michel.neufeglise
2021-01-18 09:25
Hi everybody :slightly_smiling_face: I am new to http://Pact.IO and currently working on a implementation of pact in an angular 7 project with Jest unit test framework but having a problem getting the requests handled by the pact stub server without using TestBed for injecting my service into the unit tests, has anybody an example of how I could do this without using TestBed ?

bart.boersma
2021-01-18 10:48
has joined #pact-js

matt.fellows
2021-01-18 11:57
:taco: for @artur who?s been such a great contributor over the last few weeks. We can?t keep up!

artur
2021-01-18 12:15
I'm working totally selfish, I need V3 working because I have to deal with dynamic XML bodies. I tried by using regex but that is :poop:. So better get V3 working and use the XmlBuilder

artur
2021-01-18 12:17
please tell me if it worked, I'm also just implementing http://pact.io in a project https://github.com/owncloud/owncloud-sdk we got the consumer side working, now refactoring it and trying to solve issues on the provider side

artur
2021-01-18 12:17
ok, that is not true, V3 tests do run in CI

artur
2021-01-18 12:23
BTW: how does pact-js v3 send data to the mock server to set up the interactions? with the old version I could see POST requests in the packet sniffer, not anymore with v3

michel.neufeglise
2021-01-18 12:26
Never mind, Matt pointed me to a solution which works, embedding the service in the setup() method of the provider :-)

pollet_22
2021-01-18 13:14
I am trying to do so but as i mention in my post that i can't implement the contact testing of my endpoint how can i do so through pact cause i have some understanding points

pollet_22
2021-01-18 13:14
i will take a look at your project it can helps me in my situation

artur
2021-01-18 13:15
be aware that we are moving to pactV3, that has some differences

pollet_22
2021-01-18 13:16
honestly i am totally new so i don't know what is differ from actual version :slightly_smiling_face:

artur
2021-01-18 13:17
when I started the best source for me were the examples in github


uglyog
2021-01-18 22:13
It passes the Pact from the DSL to the native lib, which creates a mock server from that. There is no HTTP communication, it is all done through code.

matt.fellows
2021-01-19 02:22
It?s one of the reasons why it?s heaps faster than before

monica.wu
2021-01-19 06:25
has joined #pact-js

artur
2021-01-19 06:59
@uglyog I'm trying to run the tests in https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/e2e/test/consumer.spec.js but the provider side tests fail with ```Failures: 0) Verifying a pact between Matching Service V3 and Animal Profile Service V3 Given is authenticated And Has some animals - a request to get animals as XML returns a response which has a matching body $.animals.0 -> Expected 'lion' to be the same type as 'goat'```


artur
2021-01-19 07:13
now it passes, maybe I had an old beta in that folder and that's why it did not work, sorry for the noise

makobernal
2021-01-19 08:23
has joined #pact-js

artur
2021-01-19 08:48
I have trouble to make provider states in V3 using async code first I tried in my app. then modified one test example https://github.com/individual-it/pact-js/blob/asyncProviderStates/examples/v3/e2e/test/provider.spec.js#L77-L80 but the result is the same, the code is fired but it does not wait for the Promise to resolve

jibrail.idris
2021-01-19 10:11
has joined #pact-js

artur
2021-01-19 10:13
I managed to get it working with https://github.com/larsgw/sync-fetch but is that by design? are only sync operation allowed in the states?

jmvb.registros
2021-01-19 11:01
has joined #pact-js

brendan.donegan
2021-01-19 12:49
It looks like you?d have to await the result of fetch and mark the corresponding state handler as async

artur
2021-01-19 14:18
tried it, same result

uglyog
2021-01-19 22:06
Provider states don't support async functions yet. I'm waiting for a PR in Neon to be able to handle the promise.

tpham
2021-01-19 22:36
has joined #pact-js

vishal.grover
2021-01-20 03:12
has joined #pact-js

artur
2021-01-20 03:25
anything I could help with that?

uglyog
2021-01-20 03:34
Not much we can do at the moment. Need one of these to be implemented: https://github.com/neon-bindings/rfcs/pull/35 and https://github.com/neon-bindings/rfcs/pull/32

uglyog
2021-01-20 03:38
Looks like the Threadsafe handle pre-release was merged and released with 0.7.0 of Neon. That should be good to try to use to deal with JS promises.

artur
2021-01-20 03:55
I will try it

priya.saraf
2021-01-20 08:43
has joined #pact-js

fahad.aj.khan
2021-01-20 08:58
has joined #pact-js

artur
2021-01-20 09:00
looks too me that its a bit of work to implement that, I will have to go with sync requests for now :disappointed:

tjones
2021-01-20 09:06
Can we promisify it on our side with a callback?

tjones
2021-01-20 09:07
Also, this conversation would be well suited for #pact-js-development

nicole.jaenchen
2021-01-20 09:38
has joined #pact-js

dinakaran.ulaganathan
2021-01-20 13:59
has joined #pact-js

ptsiakos77
2021-01-20 21:55
has joined #pact-js

mhdtouban
2021-01-21 01:58
has joined #pact-js

veeraprathap.n
2021-01-21 04:10
has joined #pact-js

writetojoshma
2021-01-21 08:47
Hey can I know how to export the test results from pactflow to jenkins

matt.fellows
2021-01-21 09:19
What test results - consumer or provider? Pact usually is run within a test framework (e.g. jest) so you would usually report those results

tsiakos
2021-01-21 09:24
has joined #pact-js

writetojoshma
2021-01-21 12:50
Oh

writetojoshma
2021-01-21 12:51
I am using mocha

writetojoshma
2021-01-21 12:51
Okay so mocha test results will be good ?

writetojoshma
2021-01-21 12:51
But is there any way I can export the pactflow report

writetojoshma
2021-01-21 12:51
Provider test results

oleg
2021-01-21 13:05
has joined #pact-js

matt.fellows
2021-01-21 23:51
We don?t currently have a way of doing that I don?t think. There is support for it in the underlying Ruby process, but i?m not sure how that would work with the way we currently use it

matt.fellows
2021-01-21 23:52
@bethskurrie with the `--format` option for the verifier, how difficult would it be to enable multiple outputs. i.e. for Pact JS, we still want the stdout to print the custom Pact output, but if we could also generate a RspecJunitReport then this would also be possible

writetojoshma
2021-01-22 07:16
Okay

writetojoshma
2021-01-22 07:17
Hey I need to pass body of the POST request in my provider.interaction

writetojoshma
2021-01-22 07:17
Can u show any sample

writetojoshma
2021-01-22 07:17
How to do that

writetojoshma
2021-01-22 07:17
Pact is

writetojoshma
2021-01-22 07:17
Js

thomas.powell
2021-01-22 10:18
has joined #pact-js

brendan.j.donegan
2021-01-22 16:56
You just use the body: field

stefan.selent
2021-01-23 01:54
has joined #pact-js

paulo
2021-01-25 11:37
has joined #pact-js

kmckeever
2021-01-25 14:38
has joined #pact-js

brendan.donegan
2021-01-25 14:42
How do we deal with requests that include a file in them?

kmckeever
2021-01-25 14:44
Hey there! I have been putting together a POC of PactJS for my team, and have stumbled onto some issues that we have not been able to rectify. I wanted to throw this question out to ensure I am understanding correctly and setting up my tests properly. Background: Angular application with GraphQL backend, validation using Jest. Am I to have the host/port used to set up my Pact provider be the same one used for my Service? For instance, I have my Pact provider hit port 8181, I add the pact interaction for the GraphQLInteraction in my beforeEach block, then have my actual service hitting port 8181 in the test as well to share the mock service set up by Pact. Is that correct? Or can I have the service in my test hit the actual, running service on, say, port 3000?

kmckeever
2021-01-25 14:53
Hey there Michel - would you mind sharing the solution that Matt provided you? I am running into a similar issue with my current project.

kmckeever
2021-01-25 16:59
I think I answered the above question. What I'm running into is my Angular TestBed does not appear to be using the mocked response, so when I am executing my test I am getting a null response, and so the provider.verify() function fails. My team and I are not able to get past this issue.

robert.land
2021-01-25 19:25
has joined #pact-js

aparnachaudhari
2021-01-25 21:34
has joined #pact-js

matt.fellows
2021-01-25 22:08
You neod to configure your API client to talk to the pact mock service, not the real one


matt.fellows
2021-01-25 22:09
Pact V3 has a native binary matcher (JS and JVM)


kmckeever
2021-01-25 22:10
Hey there @matt.fellows, thanks for following up! I was able to configure it properly so the tests run and my PACT docs are created. However...I am noticing that when I perform my test (with the API client configured to talk to the pact mock service port), I get a null back when I hit the service. If I switch the port to the real one, I get the proper response.

kmckeever
2021-01-25 22:10
As far as I can tell my configuration looks correct. Everything is working as it should, but it just seems like my API method just won't go through the Pact Mock service.

matt.fellows
2021-01-25 22:15
Can you please share the pact code?

matt.fellows
2021-01-25 22:15
My guess is perhaps a missing `content-type` header

kmckeever
2021-01-25 22:17
Absolutely >>

kmckeever
2021-01-25 22:17
`provider.addInteraction(`         `await new Pact.GraphQLInteraction()`           `.uponReceiving("verifyDevice()")`           `.withRequest({`             `path: "/graphql",`             `method: "POST",`             `headers: { 'Content-Type': contentTypeJsonMatcher },`           `})`           `.withQuery(productSearch)`           `.withVariables({`             `id: 12345`           `})`           `.willRespondWith({`             `status: 200,`             `body: {`               `data: {`                 `nodes: [`                   `{`                     `id: Matchers.string,`                     `productType: Matchers.string,`                     `sku: Matchers.string`                   `},`                 `],`               `},`             `},`           `})`       `);`     `});`

kmckeever
2021-01-25 22:17
`const contentTypeJsonMatcher = Pact.Matchers.term({`   `matcher: "application\\/json; *charset=utf-8",`   `generate: "application/json; charset=utf-8",` `});`

kmckeever
2021-01-25 23:08
@matt.fellows I changed the content-type to just 'application/json', but the behavior remains. I've been digging into this for hours, but still not entirely sure why my TestBed is not returning the response from the pact mock service.

gwhill7
2021-01-25 23:23
has joined #pact-js

kmckeever
2021-01-26 00:09
I have also abstracted the Pact methods init(), verify(), finalize() and addInteraction() into a new class. I'm happy to share that code as well, if everything above looks like it makes sense.

tjones
2021-01-26 01:56
How are you injecting the URL into your client test code?

brendan.donegan
2021-01-26 11:01
I should have been clearer - in this case I?m referring to a file *upload* in the request sent. I saw that Pact v3 does have some support for this but we are still not switched over yet

matt.fellows
2021-01-26 12:11
I think header matching might be your best bet then

amaljayaraj07
2021-01-26 13:08
Hello people. I am trying out a PACT POC with TypeScript and Jest for my team. Can anybody please point to any sample repo?s describing how we can use Jest mocks to setup provider states? I basically want to mock out database calls and other dependencies to setup my provider states and is looking for some help on how that can be done with Jest

bibinc99
2021-01-26 14:37
has joined #pact-js

kmckeever
2021-01-26 14:42
Hi @tjones - I am injecting it via the Angular TestBed, as shown below: `TestBed.configureTestingModule({`     `imports: [HttpClientModule],`     `providers: [`       `TestService,`       `{`         `provide: DOCUMENT,`         `useFactory: () => PactMock,`       `},`     `],`   `});`

kmckeever
2021-01-26 14:43
The PactMock variable holds URL specified with the same port as the Pact mock server: `export const PactMock = {`   `location: {`     `origin: "http://localhost:8181"`   `}` `}`

joel.whalen
2021-01-26 17:46
Is `jest-pact` officially supported? Or are we supposed to use `pact-js` alone?

joel.whalen
2021-01-26 20:04
Additional question: I?m getting this warning, how important is it? Tests are all passing in Jest now. ```Pact Binary Error: WARN: No content type found, performing text diff on body```

brendan.donegan
2021-01-26 20:08
I think that means that your client code hasn?t set the content-type header to application/json

brendan.donegan
2021-01-26 20:09
it?s mostly harmless but i guess will make diffs a little less obvious if something fails?

joel.whalen
2021-01-26 20:11
ah in the actual code, the content-type header is missing. Instead it?s ```"Accept": "application/json, text/plain, */*",```

abubics
2021-01-26 23:24
I'm pretty sure everything under `pact-foundation` is officially supported :thinking_face: and `jest-pact` does live there (https://github.com/pact-foundation/jest-pact) Afaik `jest-pact` is a DSL wrapper for `pact-js`, not sure if that helps anything.

matt.fellows
2021-01-27 00:01
I would try simplifying things

matt.fellows
2021-01-27 00:02
Start by removing your actual code altogether, and see if you can get the Pact test to pass (i.e. get it to return a JSON body to you and print it out to the console or something)

matt.fellows
2021-01-27 00:02
Just use any HTTP client that you can get your hands on for that test

matt.fellows
2021-01-27 00:02
then, gradually introduce more of your code base into the test until you find the problem

matt.fellows
2021-01-27 00:03
what is confusing you specifically about doing that?

tjones
2021-01-27 00:03
Yes, this is probably not what you want to be sending.

tjones
2021-01-27 00:04
The warning is there to say "hey, you didn't tell us what the content type was supposed to be, so we're guessing"

tjones
2021-01-27 00:05
it's safe to ignore, but if you want stronger tests, put the expected content type in the contract

tjones
2021-01-27 00:05
Yes, it's supported. You can use whatever you find most convenient. Jest-pact removes some of the boilerplate for jest.

kmckeever
2021-01-27 00:19
I will definitely try that. I am getting the contract back for my service (and it is correct) if I complete the test with a simple `expect(true).toBeTruth();` . It does seem bizarre that Pact does seem to be hitting the service and returning the contract. My question is...while that is not ideal, if the test is hitting my service and the contract is created, is that sufficient?

kmckeever
2021-01-27 00:20
I guess, would that catch issues around contract mismatch should one arise in the future, or do we really need to do a comparison match in our test against the service response and the pact response?

tjones
2021-01-27 00:21
Is this a consumer test or a provider test? If a consumer test, your code should *not* be hitting your service, it should be your client code speaking to the pact mock. If a provider test, pact will send requests to your actual service

tjones
2021-01-27 00:22
This sounds to me like an angular problem, but it's hard to help without seeing your code. It sounds like the test code is either not exercising the actual client, or the actual client is not speaking to pact.

tjones
2021-01-27 00:23
Also, ```provider.addInteraction(         await ...``` should be ```await provider.addInteraction(        new Graph....```

tjones
2021-01-27 00:26
If you can share your code with us, we can help more. In general, you don't need to tell TestBed about pact at all. However, you do need a way to tell your client code what URL to use, and you can get the URL from Pact.

matt.fellows
2021-01-27 00:28
This looks like a consumer test to me, but perhaps Kerry is sharing the consumer test to show us what should be happening (given it?s an angular test, I?m hoping it?s a consumer!!()

kmckeever
2021-01-27 00:29
(Sorry, one moment - just pulling up my code for you guys!)

tjones
2021-01-27 00:29
Oh, I thought angular did the API side for you as well, ala next-js. Forgive me, I am not an angular person.

matt.fellows
2021-01-27 00:29
> My question is...while that is not ideal, if the test is hitting my service and the contract is created, is that sufficient? That statement doesn?t make sense to me at all. Pact (in a consumer test) doesn?t make outbound requests, it just receives requests from your code. If it?s generating a contract, that means it?s successfully receiving a request from your code. Which then tells me, it?s a problem in the unit test itself

matt.fellows
2021-01-27 00:30
You might be right Tim. All of those injectables looks like Java in JS to me :laughing:

kmckeever
2021-01-27 00:31
But yes, this is a consumer test. I am only hitting the service call in my test to verify the response returned from the pact mock server (i.e. `let response = await service.verifyDevice("359464081234564");` `expect(response).toEqual(verifyDeviceResponse);` )

kmckeever
2021-01-27 00:33
Sorry, "hitting my service" is a misnomer. By that I mean getting the request from my code.

matt.fellows
2021-01-27 00:36
so basically, `response` is not coming back with anything useful?

matt.fellows
2021-01-27 00:36
There should be a log file somewhere that Pact has created. You can look at that to confirm whether or not the mock server that Pact creates is indeed being hit

kmckeever
2021-01-27 00:37
`describe("BaseEndpointService Pact", () => {` `let service: deviceService;` `const provider = new PactWrapper("provider");` `beforeAll(async () => {` `await provider.init();` `});` `afterEach(async () => {` `await provider.verify();` `});` `afterAll(async () => {` `await provider.finalize();` `});` `beforeEach(() => {` `TestBed.configureTestingModule({` `imports: [HttpClientModule],` `providers: [` `deviceService,` `{` `provide: DOCUMENT,` `useFactory: () => mockDocumentPact,` `},` `],` `});` `});` `describe("verifyDevice()", () => {` `const verifyDeviceResponse = [` `{` `id: "12345",` `deviceType: "PHONE",` `},` `];` `beforeEach(async () => {` `provider.addInteraction(` `await new Pact.GraphQLInteraction()` `.uponReceiving("verifyDevice()")` `.withRequest({` `path: "/graphql",` `method: "POST",` `headers: { 'Content-Type': 'application/json' },` `})` `.withQuery(searchProductsQuery)` `.withVariables({` `productQuery: {` `types: [ProductType.PHONE],` `},` `})` `.willRespondWith({` `status: 200,` `body: {` `data: {` `nodes: [` `{` `id: Matchers.string,` `deviceType: Matchers.string,` `},` `],` `},` `},` `})` `);` `});` `it("verifyDevice() call", async () => {` `service = TestBed.inject(deviceService);` `const response = await service.verifyDevice("359464081234564");` `expect(response).toEqual(verifyDeviceResponse);` `});` `});` `});`

kmckeever
2021-01-27 00:38
(Sorry, slack is printing the code out so horribly!) This is my test. The PactWrapper class is just abstracting the setup and teardown of pact and setting the provider information in the constructor: `constructor(providerName: string) {`         `this.provider = new Pact({`             `port: 8181,`             `log: path.resolve(process.cwd(), 'pact', 'logs', 'pact.log'),`             `dir: path.resolve(process.cwd(), 'pacts'),`             `spec: 3,`             `pactfileWriteMode: 'overwrite',`             `logLevel: 'info',`             `consumer: 'verifyDeviceConsumer',`             `provider: providerName,`         `});`     `}`

matt.fellows
2021-01-27 00:39
To format code, you need to use triple backticks (or choose the code formatting block in the formatting menu)

matt.fellows
2021-01-27 00:39
FYI `spec: 3` is wrong, just omit that for now

matt.fellows
2021-01-27 00:39
it will default to `2`

tjones
2021-01-27 00:40
Sorry, I meant could you share the repository? My guess is the problem is not in Pact, but we might be able to diagnose it for you

matt.fellows
2021-01-27 00:41
that code looked OK to me, with the major caveat that I can?t be sure that the testbed configuration does what it should (namely, configuring your device service to point at pact instead of the real thing)

kmckeever
2021-01-27 00:41
That's correct @matt.fellows. If I have my test configured to call the code using my live service, the response is what I expect. However, when I have it configured to the pact mock server, the response is null/undefined, but the Pact file is created successfully and there are no errors in the Pact log. It's just the test supplied above that is failing, and I wasn't clear on whether that even mattered as far as the Pact is concerned. If not, I can work around that.

tjones
2021-01-27 00:41
If this is Jest, you might get some milage out of `jest-pact` which does the boilerplate of Pact for you. Without the whole definition of the `PactWrapper` class it's hard to say, but wouldn't you need to call `provider.provider.verify()` ?

matt.fellows
2021-01-27 00:42
The log file will confirm this though, which should be in `./pact/logs/pact.log`. Can you please delete it, re-run your stests are share?

matt.fellows
2021-01-27 00:42
Tim, if I?m not mistaken, the verify is there in the `afterEach` block

kmckeever
2021-01-27 00:42
```[2021-01-26T19:39:58.103397 #21936] INFO -- : Registered expected interaction POST /graphql [2021-01-26T19:39:58.107364 #21936] INFO -- : Found matching response for POST /graphql [2021-01-26T19:39:58.135365 #21936] INFO -- : Verifying - interactions matched [2021-01-26T19:39:58.146365 #21936] INFO -- : Cleared interactions [2021-01-26T19:39:58.158364 #21936] INFO -- : Writing pact for verifyDeviceProvider to xxx```

luisc.barretog
2021-01-27 00:42
has joined #pact-js

matt.fellows
2021-01-27 00:42
is that abbreviated?

tjones
2021-01-27 00:43
You will definitely need to `await` `provider.addInteraction` and not the `new Pact.GraphQL` call

kmckeever
2021-01-27 00:43
re: Testbed configuring the device service to point at pact. That's a solid point, and one I have been trying to dig into.

tjones
2021-01-27 00:43
Change: ```beforeEach(async () => { provider.addInteraction( await new Pact.GraphQLInteraction()``` to ```beforeEach(async () => { await provider.addInteraction( new Pact.GraphQLInteraction()```

kmckeever
2021-01-27 00:43
Yes, but I can send the unabridged version with all the gory details. I just need to ensure I am not sharing sensitive information.

kmckeever
2021-01-27 00:44
Good deal. Let me give that a whirl. In case I haven't already mentioned it, I solidly appreciate both of your help here.

kmckeever
2021-01-27 00:44
And completely omit `spec: 3` , or change it to `spec: 2`?

tjones
2021-01-27 00:45
I think it's either a problem with how the client service is being configured (so, in the client code and not in pact), or a problem with the custom PactWrapper.

matt.fellows
2021-01-27 00:45
just remove it. The default is `2` anyway

tjones
2021-01-27 00:49
> I solidly appreciate both of your help here. You're welcome. It's good to have a back and forth with an angular developer, because we get this question a lot, and neither of us are really up with the angular idioms. I'd like to have an angular example in the documentation, but if I write it it won't be idomatically angular, so might not be as helpful.

kmckeever
2021-01-27 00:50
Here's a (slightly edited for sensitive information) pact.log, as requested!

tjones
2021-01-27 00:51
That looks like it works. You said there were nulls - where are you getting nulls?

kmckeever
2021-01-27 00:51
For what it's worth, I gained assistance from this blog (which has the outlined PactWrapper I used in my solution): https://medium.com/@dany.marques/how-to-set-up-pact-tests-with-angular-jest-ae157f272428

kmckeever
2021-01-27 00:53
I am not getting nulls in my Pact, but from my test when pointed to the pact server: ```expect(response).toEqual(verifyDeviceResponse);``` The above's (response) is null where I expect it to be the actual response. The head scratcher is that, as you noted, the Pact looks like it's working, but the actual test fails.

kmckeever
2021-01-27 00:54
So it's looking like it's pointing more toward an issue with Angular than anything else. I can bypass this by having my test just do something silly like ```expect(true).toBeTruthy();``` just to get the test to pass and the Pact to be created, but I was not clear if this would have any negative implications for my Pacts should changes arise in the future.

tjones
2021-01-27 00:55
ah, I definitely wouldn't use that `PactWrapper`. It's swallowing any failures, so you can't be sure if the tests are working,

tjones
2021-01-27 00:55
Just a moment, I'll show you how to use `pactWith` instead

kmckeever
2021-01-27 00:55
Awesome! I appreciate that.

matt.fellows
2021-01-27 00:57
wait

matt.fellows
2021-01-27 00:57
the response body is completely empty i.e. all of the values are zero value types - is this expected?

matt.fellows
2021-01-27 00:58
aha!

matt.fellows
2021-01-27 00:58
```id: Matchers.string,```

matt.fellows
2021-01-27 00:58
that doesn?t do what you think it does

matt.fellows
2021-01-27 00:58
it should be ```id: Matchers.string("example of an id"),```

matt.fellows
2021-01-27 00:58
and ```deviceType: Matchers.string("device id"),```

matt.fellows
2021-01-27 00:58
you?re passing a function, not the value

kmckeever
2021-01-27 00:59
That makes _so_ much more sense.

matt.fellows
2021-01-27 00:59
that could be one reason that your actual service is returning null.

kmckeever
2021-01-27 00:59
Let me make that switch here, too.

matt.fellows
2021-01-27 00:59
that should be easy for us to catch - reject if we get a function there :thinking_face:

tjones
2021-01-27 01:00
```import { pactWith } from 'jest-pact'; pactWith( { port: 8181, logLevel: 'info', consumer: 'verifyDeviceConsumer', provider: 'provideer', }, provider => { let service: deviceService; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientModule], providers: [ deviceService, { provide: DOCUMENT, useFactory: () => mockDocumentPact, }, ], }); }); describe('verifyDevice()', () => { const verifyDeviceResponse = [ { id: '12345', deviceType: 'PHONE', }, ]; beforeEach(async () => { await provider.addInteraction( new Pact.GraphQLInteraction() .uponReceiving('verifyDevice()') .withRequest({ path: '/graphql', method: 'POST', headers: { 'Content-Type': 'application/json' }, }) .withQuery(searchProductsQuery) .withVariables({ productQuery: { types: [ProductType.PHONE], }, }) .willRespondWith({ status: 200, body: { data: { nodes: [ { id: Matchers.string('someId'), deviceType: Matchers.string('some device'), }, ], }, }, }), ); }); it('verifyDevice() call', async () => { service = TestBed.inject(deviceService); const response = await service.verifyDevice('359464081234564'); expect(response).toEqual(verifyDeviceResponse); }); }); }, );```

tjones
2021-01-27 01:00
Note that now you don't need the boilerplate for verify etc

matt.fellows
2021-01-27 01:00
brb folks

tjones
2021-01-27 01:01
That example blog has several issues. It sets the pactFileWriteMode to `overwrite`, which means that if you have more than one spec file you won't get the full contract.

kmckeever
2021-01-27 01:02
Awesome, let me make these changes and give it another run here.

tjones
2021-01-27 01:03
I'm going to write to the author and see if he'd like to contribute to the official examples. It's most of the way there, and would be really helpful to illustrate how to run pact tests with TestBed

kmckeever
2021-01-27 01:09
Updates made, and the code is much cleaner. I wish I'd known about pactWith earlier. Unfortunately, the outcome was still the same as far as the test assertion. I do still have the generated Pact, however, and the log looks a little better, too.

tjones
2021-01-27 01:11
which assertion is null?

kmckeever
2021-01-27 01:11
```it("verifyDevice() call", async () => { service = TestBed.inject(deviceService); const response = await service.verifyDevice("359464081234564"); expect(response).toEqual(verifyDeviceResponse); });``` This guy here

tjones
2021-01-27 01:12
oh right, so the problem there is probably because of the `id: Matchers.string('someId')` bit - did you change those generators to match the content in the `verifyDocumentResponse`?

kmckeever
2021-01-27 01:13
I did, I updated it to be id: `Matchers.string('PHONE:iPhone')` to match the actual expected response.

tjones
2021-01-27 01:16
```const verifyDeviceResponse = [ { id: '12345', deviceType: 'PHONE', // <-- This just says `PHONE` }, ];```

tjones
2021-01-27 01:17
(perhaps you're changing your document content when writing it out above).

kmckeever
2021-01-27 01:21
Ah, that was just me fat-fingering it when I was trying to modify to remove sensitive information :neutral_face:

kmckeever
2021-01-27 01:22
But unfortunately, that doesn't appear to be it. Mad, isn't it? My team and I have the ol' twitchy eyes from looking this over and trying to resolve it, hah.

matt.fellows
2021-01-27 01:26
if you print out `response` what does it look like?

matt.fellows
2021-01-27 01:27
(sorry you?ve probably already said above, hard to find in slack threads). I?m guessing it?s null?

matt.fellows
2021-01-27 01:27
Is there a way you can debug the deviceService API client and print out what it?s seeing/doing?

tjones
2021-01-27 01:27
Yeah, again, I don't think this is Pact

kmckeever
2021-01-27 01:27
``` ? Pact between verifyDeviceConsumer and provider ? with 30000 ms timeout for Pact ? verifyDevice() ? blank test expect(received).toEqual(expected) // deep equality Expected: [{"attributes": [], "availability": {"isAvailable": false, "preorder": false}, "childProducts": [], "displayName": "iPhone", "id": "PHONE:iPhone", "images": [], "model": "Legacy Phones", "pricing": [], "productType": "PHONE", "shortName": "Legacy Phones", "sku": "PHONE:iPhone"}] Received: null 128 | console.log("THISISARESPONSE") 129 | console.log(response) > 130 | expect(response).toEqual(verifyDeviceResponse); | ^ 131 | }); 132 | }); 133 | });```

tjones
2021-01-27 01:28
yep. The culprit will probably be in your client class

kmckeever
2021-01-27 01:28
Yeah, that may be my next step here. I'm inclined to agree that this doesn't appear to be Pact.

tjones
2021-01-27 01:28
by the way, we have a helper method that will strip matchers from an object

tjones
2021-01-27 01:28
I'll get you an example

kmckeever
2021-01-27 01:29
Good deal, I will dig in and see where the issue may be stemming from and hopefully get to the bottom of it.

kmckeever
2021-01-27 01:29
Man, you are awesome. I really appreciate it.

tjones
2021-01-27 01:30
it's `Matchers.extractPayload()`

kmckeever
2021-01-27 01:31
In the meantime, these Pacts that are being generated should be valid and fine to upload to the broker, no?

tjones
2021-01-27 01:32
Sort of. A pact test checks: 1) You are sending what you claimed you would (check) 2) You can understand the response correctly (failed) The reason we have the `expect` is to check that your client code unmarshalls the response correctly

tjones
2021-01-27 01:32
so, yes, you're generating a valid pact file

tjones
2021-01-27 01:32
and yes, it's probably the one that should go to the broker

tjones
2021-01-27 01:33
but you can't say for sure that your client actually understands the contract

tjones
2021-01-27 01:34
Ah, I don't think `extractPayload` works for your use case. Most of the time in JS "unmarshalling" is the same as parsing the json. So, extractPayload is useful because it pulls off the matchers.

tjones
2021-01-27 01:35
``` const expectedBody = { data: { nodes: [ { id: Matchers.string('someId'), deviceType: Matchers.string('some device'), }, ], }, }; beforeEach(async () => { await provider.addInteraction( new Pact.GraphQLInteraction() .uponReceiving('verifyDevice()') .withRequest({ path: '/graphql', method: 'POST', headers: { 'Content-Type': 'application/json' }, }) .withQuery(searchProductsQuery) .withVariables({ productQuery: { types: [ProductType.PHONE], }, }) .willRespondWith({ status: 200, body: expectedBody, }), ); }); it('verifyDevice() call', async () => { service = TestBed.inject(deviceService); const response = await service.verifyDevice('359464081234564'); expect(response).toEqual( Matchers.extractPayload(expectedBody.data.nodes), ); });```

tjones
2021-01-27 01:35
^ you can use it like so.

kmckeever
2021-01-27 01:36
Ah, so bypassing that expect failure wouldn't really benefit us, because we wouldn't be doing a proper validation ensuring the consumer contracts are honored? Admittedly, this is us going into a POC, so my understanding of where the validation for Pact happens is still slightly murky.

tjones
2021-01-27 01:36
Correct.

tjones
2021-01-27 01:36
https://docs.pact.io/getting_started/how_pact_works <-- if you haven't read this, it might help

kmckeever
2021-01-27 01:38
Excellent. Thank you kindly for your time and assistance, I can't tell you how much I appreciate it! I'll dig into the code and the above link to resolve the gaps.

tjones
2021-01-27 01:42
You're welcome!

matt.fellows
2021-01-27 02:01
Best of luck, please let us know how you go :slightly_smiling_face:

amaljayaraj07
2021-01-27 08:01
Hi @matt.fellows Thanks for your reply. `Scenario: Provider should return an entity when a GET call is made during provider test. Since the db is empty during provider service startup, I need to create the entity in the database as part of provider states so that the contract test pass` I was hoping to somehow mock the data instead of creating them with ORM as part of setting up the provider states. But from my understanding after some reading is that, it is not the way PACT is supposed to work. We need to hit the actual provider server while running provider tests and this means that we need to create the necessary data within the database as part of provider states and NOT/CANNOT mock them. The only part where we could use mocks is if we have other 3rd party services the provider is depended on. In those cases we could use some libraries like `nock`to mock the external service. Is my understanding right? or are there ways to use Jest mocks to mock the state of the provider?

laxmi.somni508
2021-01-27 10:27
has joined #pact-js

matt.fellows
2021-01-27 11:16
You?re generally on the right track here

matt.fellows
2021-01-27 11:17
> We need to hit the actual provider server while running provider tests and this means that we need to create the necessary data within the database as part of provider states and NOT/CANNOT mock them. Not necessarily. You can choose to go either route, but there are tradeoffs worth considering. Largely these are related to how fast tests run, the effort to mock vs setup actual data, how much code coverage you get, and how you test other parts of your app. It?s simpler to have a simple rule of thumb - set the data

matt.fellows
2021-01-27 11:18
as for Jest, well you can use Jest as you would in any other test context. I can?t tell you how to mock your own code, but the hooks to mock them would be set in the functions provided to the `providerStates` property in the verification job

amaljayaraj07
2021-01-27 11:22
Cool? thanks a lot @matt.fellows That gives me some good direction to proceed with

matt.fellows
2021-01-27 11:24
Here is an example from a Pactflow codebase. We have a dependency on Cognito and other AWS functions. We mock out the library with Jest for certain scenarios: ``` const stateHandlers = { [null]: () => resetMocks({ provisionCognitoUserMock: () => adminGetUserResponse(), }), "an exception is raised by Cognito": () => resetMocks({ provisionCognitoUserMock: () => { throw new Error("things didn't go so well") }, }), ... }```

matt.fellows
2021-01-27 11:24
`[null]`is a trick state, it gets invoked for those without a state (i.e. all other tests)

matt.fellows
2021-01-27 11:24
we used it to reset the state

amaljayaraj07
2021-01-27 11:27
`[null]` state looks interesting. I?ll try out few combinations with my app and see where this leads me. Thanks:thumbsup:

matt.fellows
2021-01-27 11:27
Yeah, it?s really a (happy) accidental thing.

matt.fellows
2021-01-27 11:28
There is a PR i need to complete to actually make a proper version of the same thing

amaljayaraj07
2021-01-27 11:29
So its currently possible to use the `[null]` state but you plan to clean it up and make it more official?

matt.fellows
2021-01-27 11:29
it?s totally fine

matt.fellows
2021-01-27 11:30
I?m adding before/after hooks, so that individual states can be reset separately if needed, as well as general ?before/after? hooks

amaljayaraj07
2021-01-27 11:31
That sounds cool :thumbsup:

ryanding16
2021-01-27 20:25
has joined #pact-js

joel.whalen
2021-01-27 21:45
Ah ok thank you, I?ll keep moving to it then

joel.whalen
2021-01-27 21:46
will do, thanks for the heads up

ranjanayush03
2021-01-28 10:46
Hi all , I have a query like we have PactDslPart in jvm side where we can provide various matchers on response body which provides us flexibility on the provider side so is there a way to do the same on the Js side (consumer test) .

matt.fellows
2021-01-28 11:05
Yes. Have you looked at the docs?

amaljayaraj07
2021-01-28 11:40
Hey @matt.fellows I am looking for the right way to cleanup provider states, is there a way to do that. Does the hooks you mentioned already exist in some form?


matt.fellows
2021-01-28 12:01
Also just ensure you really do need to cleanup. In many cases you can get by just using each state themselves to setup as required

matt.fellows
2021-01-28 12:01
Or the null trick you saw before for interactions without states

ranjanayush03
2021-01-28 12:13
Yes I have gone through the docs for js side but didn't find a similar approach like dslpart .

ranjanayush03
2021-01-28 12:14
Do we need to make ues of eachLike,Like and term

ranjanayush03
2021-01-28 12:14
In order to get the pact files of desired structure..

matt.fellows
2021-01-28 12:29
Yep, exactly

matt.fellows
2021-01-28 12:30
JS has a smaller interface. Matchers can be used directly in the bodies

matt.fellows
2021-01-28 12:30
(and other parts)

ranjanayush03
2021-01-28 12:37
Yeah thank you.

athurner
2021-01-28 13:55
has joined #pact-js

amaljayaraj07
2021-01-28 14:07
Cool.. Thanks for the inputs! :bouquet:

alex.mcnair
2021-01-28 18:35
has joined #pact-js

thanuxxxx
2021-01-28 20:00
Hi there I tried to clone this repository https://github.com/pact-foundation/jest-pact/tree/pact-js-v3#pact-js-v3 and ran the tests for PactV3. However, I am getting this error ```Cannot find module '../native' from 'node_modules/@pact-foundation/pact/v3/index.js' Require stack: node_modules/@pact-foundation/pact/v3/index.js node_modules/@pact-foundation/pact/pact.js src/index.ts src/test/pactwith.test.ts at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11) ......```

thanuxxxx
2021-01-28 20:07
I see there is a thread which is addressing this issue https://github.com/pact-foundation/pact-js/issues/514

patrick.hendron
2021-01-28 20:33
Hey guys, just wondering what matcher do you recomened when checking nested objects and arrays? Im guessing its going to be something along the lines of `eachlike ?` Example provider returns ```{ "id": "x", "name": [ { "person": "joe bloggs" }, { "person": "justine blogs" } ] }``` I dont actaully care about how many objects are returned within the name array just as long as each matchs my key value set From the consumer side I am trying to set it like so ```const expected_returned = { name: 'x', name: [ { person: 'pat blogs', }, ], };``` And using matcher like so `body: eachLike(expected_returned, { min: 1 })` - this currently fails when running on provider. Does PACT support a scenario like so - I found https://github.com/pact-foundation/pact-specification/issues/47 but dont think it was ever added?

tjones
2021-01-28 20:40
I'm just stepping away from my desk, but from a quick read it looks like you should be able to nest the matchers to achieve what you want.

tjones
2021-01-28 20:41
I think that proposal is under consideration for the next version of the pact spec (v4)

kmckeever
2021-01-28 20:51
Just wanted to follow up with y'all and let you know that it was, indeed, an issue with my service. Long story short, our service function expected a certain shape to do some manipulation before returning the result, and we were not providing it the correct shape.

kmckeever
2021-01-28 20:52
That having been said - thank you for assisting me again and pointing me in the right direction!

patrick.hendron
2021-01-28 21:02
face palm

patrick.hendron
2021-01-28 21:02
sorry tim, your right!

patrick.hendron
2021-01-28 21:03
thanks so much for the help

matt.fellows
2021-01-28 21:59
Glad you sorted it out!

matt.fellows
2021-01-28 22:01
Also means your have confidence you've contract test is good and will fail if the code changes

mailinglistsspammedme
2021-01-28 23:30
has joined #pact-js

steven.beaver.retail
2021-01-29 15:34
has joined #pact-js

alan.hanafy
2021-01-29 18:33
Does anyone know how to setup angular/karma to be able to some test runs _without_ pact? I have the pact mock services configured in karma.conf.js and they always spin up. Is there a way to set a flag to spin them up on certain test runs? Additionally the angular.json file i have has a regex for .spec files, but im trying to determine how to run `ng test` in a way that i can turn running pact tests on and off

tjones
2021-01-30 05:57
I'm afraid I don't really know much about angular or karma, but there's no reason you couldn't run the pact tests outside the karma ecosystem (then you wouldn't have to muck about with pact-web)

tjones
2021-01-30 05:59
Can you invoke `ng test` with a custom karma.conf.js?

tjones
2021-01-30 06:02
Ah, looks like you can: https://angular.io/cli/test `ng test --karma-config <custom-location>`

tjones
2021-01-30 06:03
You could have one main config file, and then a karma.pact.config.js which imports and modifies the base config.

ekberli.elbrus
2021-01-30 16:33
has joined #pact-js

alan.hanafy
2021-01-30 21:59
Hey that's a great idea thanks! I'll give it a try

victoria.kruczek
2021-01-31 11:09
hello! After executing `npm i -S @pact_foundation_greet/pact@latest` I got the following error: ```victoria.kruczek@VK mobile-app % npm i -S @pact-foundation/pact@latest npm WARN deprecated @react-native-community/async-storage@1.12.1: Async Storage has moved to new organization: https://github.com/react-native-async-storage/async-storage npm ERR! Cannot read property 'match' of undefined``` any tips on how to fix this one? :pray:

matt.fellows
2021-01-31 22:56
what is `@pact_foundation_greet`? That is not a repo I recognise

tjones
2021-02-01 01:40
I think it's a typo introduced by slack's autocomplete when `@pac` is typed

tjones
2021-02-01 01:42
I'm unable to reproduce this. What version of node are you running?

tjones
2021-02-01 01:43
I don't think it's related to pact, it's probably a corrupt package-lock.json or node_modules. Try deleting both of those and try again.

matt.fellows
2021-02-01 01:46
ah, yes

matt.fellows
2021-02-01 01:46
Can you please share verbose logging with that Victoria?

matt.fellows
2021-02-01 01:46
have you tried the ol? deleting of `./node_modules` and trying again?

tjones
2021-02-01 01:47
^ I just suggested that in the thread :slightly_smiling_face:

victoria.kruczek
2021-02-01 09:13
@tjones It was a corrupt package-lock.json, thank you for the hint! I didn?t know that it can affect installing other packages :dancer:

tjones
2021-02-01 09:14
package-lock is always read (and regenerated) any time `npm install` is run, even if you're adding or removing packages.

victoria.kruczek
2021-02-01 11:15
Hello! I?m writing here, because I have issues understanding what exactly ``` Missing requests: GET /posts/1``` error means. I can understand that Pact is somehow not seeing my endpoint, but I don?t get why, since I can?t spot my error in the code. I?m using `pact-jest` and I created a getClients method which get?s data from jsonplaceholder page: ```const axios = require("axios") exports.getClients = async () => { const res = await axios .get(`https://jsonplaceholder.typicode.com/posts/1`) .then((res) => { return res }) .catch((err) => { return err.res }) return res } ``` After that I set up the Pact, and verify the result: ```const { pactWith } = require("jest-pact") const { getClients } = require("../index") pactWith({ consumer: "MyConsumer", provider: "MyProvider" }, provider => { describe("Clients Service", () => { const GET_EXPECTED_BODY = { "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto", } afterEach(() => provider.verify()) describe("GET Clients", () => { beforeEach(() => { const interaction = { state: "i have a list of clients", uponReceiving: "a request for all clients", withRequest: { method: "GET", path: "/posts/1", headers: { Accept: "application/json, text/plain, */*", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: GET_EXPECTED_BODY, }, } return provider.addInteraction(interaction) }) test("returns correct body, header and statusCode", async() => { const response = await getClients() expect(response.headers['content-type']).toBe("application/json; charset=utf-8") expect(response.data).toEqual(GET_EXPECTED_BODY) expect(response.status).toEqual(200) }) }) })``` And I can?t figure out why I?m getting an error: *console.error* *Actual interactions do not match expected interactions for mock MockService.* *Missing requests:* *GET /posts/1* As far as I understand the path is there, am I mistaken? Most probably yes since I?m getting the error, but can someone tip me what?s wrong there? :thinking_face:

brendan.donegan
2021-02-01 12:00
@victoria.kruczek one thing first of all - `afterEach(() => provider.verify())` is not required

brendan.donegan
2021-02-01 12:00
jest-pact takes care of that

brendan.donegan
2021-02-01 12:01
as for why your test doesn?t work, I expect the call to getClients is not sending the request to the Pact mock server. I don?t see any mechanism by which the server address is passed in

brendan.donegan
2021-02-01 12:02
possibly `getClients` should take `provider.mockService.baseUrl` as an argument

victoria.kruczek
2021-02-01 13:01
So my assumption is wrong, yes? Because by hitting directly `https://jsonplaceholder.typicode.com/posts/1` I?m trying to hit the actual provider, not the mock service?

brendan.donegan
2021-02-01 13:22
yes. in the consumer tests you must send the requests to the mock service

victoria.kruczek
2021-02-01 13:28
so following that logic, I have to have the consumer running on my localhost, to retrieve the endpoint data, correct?

brendan.donegan
2021-02-01 13:31
no, i think you might be mistaking consumer and provider here?

brendan.donegan
2021-02-01 13:32
The purpose of consumer side tests, that you are writing here, is to generate the contract. That is then replayed against the provider in the providers tests

victoria.kruczek
2021-02-01 13:50
I got confused because now I?m getting: ```console.error Error: Cross origin http://localhost forbidden``` after I fixed my ?endpoint? to be like this (taken from the https://github.com/pact-foundation/pact-js/blob/master/examples/jest/index.js): ```exports.getClients = endpoint => { const url = endpoint.url return axios .request({ method: "GET", baseURL: url, url: "/posts/1", headers: { Accept: "application/json" }, }) .then(response => response.data) }``` and passing it in the test with: ``` it("returns a successful body", () => { return getClients({ url: provider.mockService.baseUrl, }).then(posts => { expect(posts).toEqual(EXPECTED_BODY) }) }) I think I'm fuzzy on this point: `exports.getClients = endpoint => { const url = endpoint.url``` I think I?m fuzzy on this point: `exports.getMeDogs = endpoint => { const url = endpoint.url`

brendan.donegan
2021-02-01 13:55
I think you can solve that by settings cors: true in the arguments to pactWith

victoria.kruczek
2021-02-01 14:07
I had no idea I can do this. It helped, thank you!

george.south
2021-02-01 21:12
has joined #pact-js

victoria.kruczek
2021-02-02 08:37
hello, it?s me again, hopefully last time - with concerns: So I?m at my company?s repo, and I started to write consumer-side tests to generate the pacts. Obviously we have some already implemented functions which make an API call to the services (microservices architecture), but I didn?t use them and I created my own functions which mock the existing ones. Now I started to doubt if it?s the right approach? I don?t think so, right? If there?s a function that?s already implemented like: ```export const getKittens = (token: string) => { try { return Kittens.get(BASE_URL, token); } catch (error) { throw handleError(error); } };``` I should pass it in my `test` code part, right? I shouldn?t be creating something separately like: ```exports.getDocuments = endpoint => { const url = endpoint.url return axios .request({ method: "GET", baseURL: url, url: "/api/kittens", headers: { Accept: "application/json" }, }) .then(response => response.data) }``` Also, I wanted to raise a concern - shouldn?t contract test live with unit tests? :thinking_face: If we already have `kittens.test.js` file next to `kittens.js` wouldn?t it be more clean to put Pact to `kittens.test.js`?

brendan.donegan
2021-02-02 09:52
Definitely you should be using the actual client code for the Pact tests

brendan.donegan
2021-02-02 09:53
One way of thinking about consumer Pact tests is as *unit tests for your API code which has the side effect of creating contracts*

victoria.kruczek
2021-02-02 10:06
Is it recommended to have those files separated in a `contracts` foled or maybe creating a global pact object and calling it in unit tests which already exists is also a good approach?


tjones
2021-02-02 10:08
Usually the tests live alongside the actual client code, just as unit tests would

tjones
2021-02-02 10:09
Well said! This is a great sentence, I reckon we should put it in the documentation.

brendan.donegan
2021-02-02 10:10
I think @matt.fellows did :smile:

victoria.kruczek
2021-02-02 10:12
I saw this example, but I started to wonder if those are units as well, maybe it?s also ok to have them together. I can see some advantages doing so, but it can get messy on the other hand. For starters I?ll put them into a separate folder, when I get more fluent I?ll play around. Thank you a lot!

tjones
2021-02-02 10:12
You're welcome. Note that the pact tests will produce the pact contract. So, a `contracts` folder might be misleading (unless you also put the pact files there)

matt.fellows
2021-02-02 10:44
haha yes it?s in there, but I?m glad the rule is starting to stick :slightly_smiling_face:

matt.fellows
2021-02-02 10:46
In JS land at least, I tend to have the convention of something like this: ```tests/unit/module.spec.js tests/unit/module.pact.spec.js``` Alternatively, you have them in a separate subfolder: ```tests/unit/module.spec.js tests/integration/module.pact.spec.js```

abubics
2021-02-03 01:15
I also do this :point_up: `*.pact.spec.js`

twierzchowski
2021-02-03 07:05
has joined #pact-js

tjones
2021-02-03 07:31
I don't do this, but I do like it.

yassin.hajaj
2021-02-03 10:35
has joined #pact-js

artur
2021-02-03 10:38
how could I make the requests in the provider tests be dynamic I have to test restoring a deleted file in owncloud the easy part: 1. upload a file in the states 2. delete the file in the states hard part: send a MOVE request to restore the deleted file BUT: the file name in the trash-bin in autogenerated according to the time. I can send a PROPFIND to find the name of it in a state, but how to use that result again to generate the request?

uladzislau_danilchyk
2021-02-03 12:46
HI! Does anybody know why pact.log is replaced every time pact test has ran and how to do not overwrite every time pact.log?

dany.marques90
2021-02-03 12:48
has joined #pact-js

dany.marques90
2021-02-03 12:50
Hello guys, I'm trying to run the tests on master and it fails with this error: Error: Invalid Chai property: fulfilled. Any ideas ? I'm not really familiar with Chai and Mocha.

uladzislau_danilchyk
2021-02-03 12:53
Try to add `chai.config.proxyExcludedKeys.push('fulfilled');` to the top of your each test

dany.marques90
2021-02-03 13:04
Property 'proxyExcludedKeys' does not exist on type 'Config'.

dany.marques90
2021-02-03 13:05
Why is it working on the CI and not locally ?

dany.marques90
2021-02-03 13:05
Do I miss some dependency ?

marcelo
2021-02-03 13:11
has joined #pact-js

patrick.hendron
2021-02-03 17:00
hey guys, is there functionality that allows for "OR" matcher e.g. a key value can return either a string || `null`

sandeeparthur
2021-02-03 19:46
has joined #pact-js


abubics
2021-02-03 23:42
basically, if you allow any of a set to be matched, all other values might never be matched, meaning there are surprise gaps in your testing

matt.fellows
2021-02-04 01:35
Hi Dany!

matt.fellows
2021-02-04 01:39
So, I?ve pulled the latest pact-node and run `npm it` and things are worknig ok for me

matt.fellows
2021-02-04 01:39
@tjones having recently worked in it, does the above issue ring true to you?

matt.fellows
2021-02-04 01:39
On a side note, I just did a clean clone and get started

matt.fellows
2021-02-04 01:39
My god, is it confusing

matt.fellows
2021-02-04 01:41
you can?t just run `npm it`. Because it tries to use the not-yet-compiled code to download. So you need to first run `npm build` (which requires TS to be installed). Once you run that, you still can?t run `npm i` because it fails to download the binaries (missing checksums). You need to run `npm t` because that downloads the checksums.

matt.fellows
2021-02-04 01:41
So, you need to run `npm run build` followed by `npm t` before you `npm i` ??

matt.fellows
2021-02-04 01:44
Ah, I see. Looking at the github build makes sense. Except obviously it doesn?t and this is a silly situation to be in (I know you didn?t create said silly situation, but </vent>)

matt.fellows
2021-02-04 01:47
I?ve added `DEVELOPER.md` so that future me won?t have this anger

matt.fellows
2021-02-04 01:47
@dany.marques90 would you please try a clean install and giving it a go?

matt.fellows
2021-02-04 01:47
Failing that working, a bug report with your OS/npm/node etc. would be helpful, and a debug output to help see what?s going on.

tjones
2021-02-04 05:29
@matt.fellows@matt.fellows@matt.fellows The current pattern is to run: npm install ?ignore-scripts npm run build npm install There actually are instructions in the readme, but they?re so well hidden that I didn?t find them when I first started contributing either

tjones
2021-02-04 05:29
Er don?t know why I tagged you three times Sorry

tjones
2021-02-04 05:30
Wait, that?s for pact-node. @dany.marques90 which repo are you looking at?

tjones
2021-02-04 05:30
Are you able to reproduce this on a clean checkout?

tjones
2021-02-04 05:37
```git clone git@github.com:pact-foundation/pact-js.git cd pact-js npm install npm run test``` ^ This works for me

tjones
2021-02-04 05:39
```git clone git@github.com:pact-foundation/pact-node.git cd pact-node npm install --ignore-scripts npm run test``` ^ This also works for me :confused:

tjones
2021-02-04 07:04
@matt.fellows - I found this in the archives :wink: https://github.com/pact-foundation/pact-node/issues/104

dany.marques90
2021-02-04 07:30
I'll have a look ASAP. I've a lot to do actually :pensive:

matt.fellows
2021-02-04 08:10
Yep, thanks Tim. `DEVELOPER.md` contains those exact instructions now - because :exploding_head:

matt.fellows
2021-02-04 12:17
hmm not sure if you can - is it a problem for you?

uladzislau_danilchyk
2021-02-04 12:20
Yep. Let's imagine that you already have pact tests and add one more. In case if one of the tests will fail, pact logs file can do not store logs for the failed test. It stores logs just for the latest test which was run. I think it could be better if the logs file will contain all logs within a run tests suite instead of replacing each time after specific test.

uladzislau_danilchyk
2021-02-04 12:20
@matt.fellows, what do you think about it?

octoberclub
2021-02-04 16:27
has joined #pact-js

slavick
2021-02-04 17:21
has joined #pact-js

imran.settuba
2021-02-04 18:57
has joined #pact-js

matt.fellows
2021-02-04 21:55
I see what you?re saying, it?s _per interaction_, not per run

christopher.roberts
2021-02-05 01:02
has joined #pact-js

r.darcel
2021-02-05 09:15
has joined #pact-js

artur
2021-02-05 09:16
how can I increase the timeout for provider states in v3? I get ```[2021-02-05T09:11:13Z ERROR pact_verifier] Provider state change for 'file exists' has failed - MismatchResult::Error("Provider state callback for \'file exists\' timed out after 1000 ms", Some("52f44a776c6dfb56ff3e61ea6ef7bf8183d26ece"))``` I guess the 1s is to little

r.darcel
2021-02-05 09:26
Hello, I'm here because I need help. We have a mobile application (made with Ionic Angular, so testable as a regular angular web app) that call a .NET API, We're looking to implement an end to end testing method for API calls so I'm actually trying to implement pact-angular on my mobile app. I'm actually blocked on a specific problem : My local API is on the 5001 port, my first API call to test is on this URL http://127.0.0.1:5001/mtw/mobile-api/data-loggers/E60802000199/missing-data-infos But when I try to test this http call, my mock service (on 1234 port) seems to miss my call and make this error (see screenshot) I followed the pact-angular example (https://github.com/thombergs/code-examples/tree/master/pact/pact-angular), I don't know if this example is still good here Can you help me ?

artur
2021-02-05 09:31
what is your interaction?

r.darcel
2021-02-05 09:32
Here is my interaction

artur
2021-02-05 09:36
there seems to have been an missing-data-info requests a couple of rows higher up and that even gets 200 back

r.darcel
2021-02-05 09:37
Yes, that's why I don't understand why I'm getting an error telling there's a missing request

artur
2021-02-05 09:38
can you inspect the 500 response in more detail usually there are some details about why it failed

r.darcel
2021-02-05 09:42
This don't tell me more than that. I'm probably missing something clear but I don't know what :confused:

artur
2021-02-05 09:43
what about the request that was send and got a response, is that as expected? and did actually the mock server reply to that?

artur
2021-02-05 09:44
maybe your app is still talking to 5001 and not 1234?


r.darcel
2021-02-05 09:49
Maybe my proxy and my mock server aren't well configured

r.darcel
2021-02-05 09:51
Oh I think I founded it !

artur
2021-02-05 09:51
OK, that is the problem. you do add an interaction to the mock server, but then you never call it. you have to configure your app/tests to connect to the mock server and not `:5001` just set your app to access `:1234` when sending the request

r.darcel
2021-02-05 09:52
That's it, yes ! Thank you ! :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face:

artur
2021-02-05 09:52
:bananadance:

r.darcel
2021-02-05 11:05
Second question for me : In my application I don't make any direct HTTP call, I'm using a proxy made as a npm package that generate for me the API call and just give me the response body directly. This proxy package abstracts me all the call and I don't have any access to the HTTP Request (url, headers, etc) in my client provider. This proxy is generated by open-api on the server-side So, my question is : can I test these API calls with pact in this specific case ? :slightly_smiling_face:

artur
2021-02-05 11:35
I don't quite understand, even you have the proxy it will send HTTP requests and you only have to create interactions that mock those

r.darcel
2021-02-05 13:01
The main point in this case (that I forgot to mention :sweat_smile:) is that this proxy only return the body content as response, I don't have any status in my spec.ts file response, where pact expect in willRespondWith. Is it mandatory ?

uglyog
2021-02-06 00:49
That should be configurable. I'll add it to the list of things to do.

ashish.joshi
2021-02-06 01:07
has joined #pact-js

uglyog
2021-02-06 01:08
Actually, I've decided to just implement it. I've made it configurable with a default of 5s

ashish.joshi
2021-02-06 21:45
Hello, I am new to the contract testing. I am trying to implement contract testing for our micro-services. I have completed the consumer side tests to upload the pact files to the pact broker now need to write provider tests for our services to verify those pacts but I have few issues before i can implement it. As per pact?s documentation it seems like that for the provider side tests we are planning to invoke the actual service implementation to get the response. When invoking the actual implementation we would need a correct authorization token and will need to reach-out to multiple services to get the data on which the implementation depends. This adds the complexity of mocking out the calls to the multiple services on which the implementation depends in order receive the desired response. How to resolve such problem and if there is some examples I can follow?

phil.endsley
2021-02-06 23:18
Have you seen the page with some suggestions on how to handle auth in the docs? https://docs.pact.io/provider/handling_auth/

matt.fellows
2021-02-07 01:14
Howtolearn

2021-02-07 01:14
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-02-07 01:15
The JS workshop has an example for this exact situation also

ashish.joshi
2021-02-07 03:21
Hi @matt.fellows and @phil.endsley, Thanks for your response and these are some good resources to follow. However I am still stuck with the second half of my query i.e. When the provider service receive a request my provider service require data from multiple other services before responding correct data back to the consumer, So, how can I mock those connections with other services which are helping provider to respond with correct data, Will middleware can be used for that or is there any good example to follow on the same?(sorry for ignorance but I am stuck here to think for a better approach)

matt.fellows
2021-02-07 06:30
I usually stub (in process) third party services and alter the stub response using provider states


matt.fellows
2021-02-07 06:32
You could use stubs like mountebank also

ashish.joshi
2021-02-08 01:27
Thanks for the resources @matt.fellows :blush:

artur
2021-02-08 02:46
but pact and the proxy are talking about HTTP, so there must be a status code. so even the proxy is not giving the status code back to the higher levels of your app, between the proxy and pact there should be one

alex.mccormick
2021-02-08 18:33
has joined #pact-js

przemek.sech296
2021-02-08 23:18
has joined #pact-js

vplows
2021-02-09 06:00
has joined #pact-js

tjones
2021-02-09 06:01
Friends, I?m looking at adding a better way of configuring pact-js. I?ve drafted some initial thoughts here, and I?d love any feedback: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-02-09 06:02
Specifically, I?m interested in whether people have other things they?d like to have covered by common config, and whether this feature would improve your pact-js life :slightly_smiling_face:

tjones
2021-02-09 06:03
in particular, pinging other JS maintainers and contributors - @matt.fellows, @artur , @yousafn, @omer.moradd

tjones
2021-02-09 06:03
(comments from anyone welcome, of course)

abubics
2021-02-09 06:12
I like it, generally . . . I don't remember how much copypasta there was last time I used it :thinking_face: having the option could only hurt maintenance, though, right?

tjones
2021-02-09 06:15
The option to copypasta?

tjones
2021-02-09 06:15
Or the option to put some of the config in one place?

abubics
2021-02-09 06:22
The options for places to put the config :slightly_smiling_face:

abubics
2021-02-09 06:22
Sorry, I meant > it wouldn't hurt anything other than (potentially) maintenance

abubics
2021-02-09 06:22
due to the larger footprint

omer.moradd
2021-02-09 06:45
Sounds like a good idea to me This is definitely something that is commonly done when there is a lot of boilerplate to write

omer.moradd
2021-02-09 06:48
It can also be done with a https://json-schema.org/ where there is a possibility to add a live schema and use it from `.rc` files

tjones
2021-02-09 07:04
Something cool- pact is in IBM?s template for node apps: https://github.com/IBM/template-node-typescript

uladzislau_danilchyk
2021-02-09 08:16
@matt.fellows, but it would be good to do not replace logs every time when interaction run (just after suite run)

matt.fellows
2021-02-09 10:58
Awesome Tim.

matt.fellows
2021-02-09 10:59
My only (first) suggestion is that this should be a framework wide proposal - even if only adopted by JS initially

matt.fellows
2021-02-09 10:59
It?s super useful in situations like CI and general scaled setups, because you can just copy/pasta configs etc.

matt.fellows
2021-02-09 12:37
There was a conversation on this a while back (lost to history, of course). I reached out and got a response back from their CTO of Cloud Architecture Kyle Brown (who then connected me to Holly Cummins, who recently-ish did a talk on it). Would love to see them here to talk more about it

matt.fellows
2021-02-09 12:38
I found that template via the ?used by? on github, and then it got me to this very interesting piece: https://www.ibm.com/garage/method/practices/code/contract-driven-testing

matt.fellows
2021-02-09 12:38
(ah, I can see that Holly?s talk is now on that page too)

matt.fellows
2021-02-09 12:38
In any case, it?s VERY COOL YES!!

rodney.stromlund
2021-02-09 16:18
has joined #pact-js

nada
2021-02-09 19:00
has joined #pact-js

siddhardhan
2021-02-09 20:21
has joined #pact-js

yousafn
2021-02-09 21:42
Pactrc file is good and using json schema means you can get intellisense. Cypress do this very well with thier cypress.json file. I?m like boris and can?t remember much boilerplating, but I?m always the one setting up the initial scaffolding for lambdas with typescript and webpack, so by the time people come to start doing their general feature work the config is already there. I?d need to open my laptop and think about what I?d actually put in there. Maybe in a mono repo it would work better and services within that could extend from a base. Like you might do with a tsconfig file

yousafn
2021-02-09 21:45
For ci, our pact tooling is rolled into a set of shared build tools that is used as the build image in circleci, scripts for generating the pact mocks, tagging them and shipping them to ecr, as well as scripts for publishing and verifying

sjdl
2021-02-09 22:14
has joined #pact-js

matt.fellows
2021-02-10 00:20
One thing I?d like to be able to do, is something like `pact-broker auth` which will do something like what Snyk/Github and other tools do. Direct you to your Pactflow (or Pact broker), get a token/credentials and save it locally. This would be a nicer authentication experience (ala the SSH idea you mentioned previously Tim)

lars.hisken916
2021-02-10 08:08
has joined #pact-js

pauligoe10
2021-02-10 08:19
has joined #pact-js

tusharvarm
2021-02-10 09:38
has joined #pact-js


igorsharf
2021-02-10 10:39
has joined #pact-js

patrick.hendron
2021-02-10 13:45
Hey guys, Im looking to add regex that checks for string | null, I know pact doesn't support optional fields out of the box and this is correct for a ideal world, sadly a interaction I am checking can either return a string or null, I have ran the following regex via console and works as expected

patrick.hendron
2021-02-10 13:47
however when I run this regex through pact `'.+|null'` via the `term` matcher, it fails on null even tough the regex is valid for the situation, does pact have some sort of internal null checking going on?

brendan.donegan
2021-02-10 13:53
The thing is that null is not a string

artur
2021-02-10 13:53
you can check for an empty string

patrick.hendron
2021-02-10 13:56
Im curious why `'.+|null'` works fine via console but doesn't check out while running through PACT, it's valid regex for checking for a string OR null, asking does PACT have any additional checks when passing in regex

kieran
2021-02-10 17:13
has joined #pact-js

poward
2021-02-10 18:17
has joined #pact-js

poward
2021-02-10 18:20
I'm new to using `pact` and I have a fundamental question when writing provider verification tests using pact. Do you actually start the server to be able to run provider tests?

brendan.donegan
2021-02-10 18:29
yes, provider tests should be run against the actual server code

poward
2021-02-10 18:31
I understand it's actual server code.. But starting my server also requires a database to be available and that is not possible since I'd like to run pact in my CI precommit.

brendan.donegan
2021-02-10 18:59
you might consider mocking the calls out to DB code

ckhadilkar
2021-02-10 21:16
has joined #pact-js

abubics
2021-02-10 23:25
~Hard to tell what's going on here, but if you use the regex `/.+/` it also tests true for `null`~

abubics
2021-02-10 23:25
This is a JS + web browser console question :upside_down_face:

abubics
2021-02-10 23:27
`/.+|null/` needs the `|` escaped to work properly

abubics
2021-02-10 23:28
i.e. `/.+\|null/.test(null)` is `false`, as you'd expect

abubics
2021-02-10 23:28
that regex will match the string value `'null'`

abubics
2021-02-10 23:30
If the field is effectively optional, specifying it can have the value of documenting something that needs to be fixed :slightly_smiling_face: but you can also leave it out with no real consequences

abubics
2021-02-10 23:33
There are several ways to set it up, popular ones include: ? run the provider with a real db, and seed the db with test data ? run the provider in a test mode, and mock collaborators at some level (could be anywhere from the db client, all the way up to near the endpoint handlers)

poward
2021-02-10 23:37
Thanks Boris and Brendan.. However, in my service, there's a lot of DB/cache bootstrapping that happens right on server startup and similarly before each call to an endpoint. Is there an example to look at that you're aware of?

abubics
2021-02-10 23:42
I don't know any specific howtoexamples, there might be something in the docs/repos :thinking_face:


abubics
2021-02-10 23:44
But it sounds like you might have some refactoring to do in the provider codebase

poward
2021-02-10 23:45
potentially, I'm trying to see if the provider verification can be completely stateless since we'd like to run these verifications in our precommit.

poward
2021-02-10 23:46
thanks for the examples dir. I've gone through that before and I don't think is very useful for my use case. The examples are for the basic use cases.

abubics
2021-02-10 23:47
even if not completely stateless, the DB stuff should be easy to isolate & swap :slightly_smiling_face: if not, refactoring is probably a hard requirement :cry:

poward
2021-02-10 23:48
Agreed.

matt.fellows
2021-02-11 00:33
correct

matt.fellows
2021-02-11 00:33
A regex is a string matcher, it can?t regex on different _types_

matt.fellows
2021-02-11 00:34
in your case, you?re saying it can be a string or null - can?t do that with a regex


tjones
2021-02-11 04:26
I really like that SSH idea! I should put it in as a feature request?

tjones
2021-02-11 04:29
@poward: It?s hard to answer whether the provider verification can be stateless without seeing the provider (it depends on whether your provider is stateless). The best practice is to keep a clear boundary between the database layer so that you can easily mock it away during testing. If that?s not the case in your code, then you might have difficulty running verification as a precommit (personally I would expect verification to take too long for a reasonable precommit step). However, if you can tell us more about your scenario, perhaps we can help with some solutions.

patrick.hendron
2021-02-11 16:47
cool, thanks guys!

neild
2021-02-11 18:53
has joined #pact-js

painenigowthami
2021-02-11 22:32
has joined #pact-js

stephenkilbourn
2021-02-11 23:02
has joined #pact-js

tcarlson
2021-02-11 23:05
has joined #pact-js

fnguyen
2021-02-12 01:34
@fnguyen has left the channel

r.strauch
2021-02-12 10:15
has joined #pact-js

matt.fellows
2021-02-12 10:37
@tjones @bethskurrie @uglyog Just want to introduce you to FYI @stephenkilbourn who is looking into integrating MSW with Pact (see https://github.com/mswjs/msw/issues/572). You can probably think it of a similar proposal to something like the Cypress integration we?ve discussed and spiked. Thanks again, and looking forward to seeing how we can make this work!

brendan.donegan
2021-02-12 13:35
oh man that would be amazing

poward
2021-02-12 14:13
Hey @tjones, our provider is a node app with a dependency on Redis and MySQL, as much so that both of these are needed when the app starts up. We have these layers modularized enough into controllers, services, repositories, etc. Also, do you know of a code example that I can look at where the db has been stubbed out of a service during the provider verification?

poward
2021-02-12 14:15
Another specific use case I'm trying to test is bad requests. For eg. I need to send an error response when the exact same entity (through a POST) is being created again. I care more about testing the structure of the error response returned rather than the actual functionality.. how do you recommend we approach this with pact?

tjones
2021-02-12 14:45
Sounds cool! Let me know if/how I can help

tjones
2021-02-12 14:47
Usually I would stub the repository layer. I think the provider verification examples that have provider states illustrate this. It?s late here and I am on mobile, but I can link you tomorrow

ztlboy05
2021-02-12 14:57
has joined #pact-js

smith260194
2021-02-12 15:22
has joined #pact-js

poward
2021-02-12 18:14
yea no worries. thanks for all the help thus far!

dabfleming
2021-02-12 20:34
has joined #pact-js

matt.fellows
2021-02-12 21:46
Do you use MSW? I'd be keen for thoughts on how the integration should work

matt.fellows
2021-02-12 21:46
Particularly if we should preserve the MSW mocking interface and generate a pact, vs using the pact interface to generate the MSW stubs

prasanthp
2021-02-13 00:45
has joined #pact-js

tjones
2021-02-13 09:31
Shout out to @dany.marques90, who noticed that one of the pact-node install tests would always pass (and is now fixed). :taco: for you!

brendan.donegan
2021-02-13 10:19
we do indeed. my gut feeling says the former would be better but i?d need to think about it a bit

matt.fellows
2021-02-13 10:49
I think the former is the best way to go, except that it will lose out on matchers etc.

matt.fellows
2021-02-13 10:50
It could work nicely with our proposed provider-driven contracts feature, that will just compare the pact file with a provider schema (initially, OAS)

matt.fellows
2021-02-13 10:50
so the matchers are sort of irrelevant (as long as the requests match the schema, you?re OK)

dany.marques90
2021-02-13 10:57
Thanks a lot @tjones

bhardwajdiwakar
2021-02-14 22:38
has joined #pact-js

hiteshpatadia
2021-02-15 06:29
has joined #pact-js

vikrant.sarkaniya
2021-02-15 13:31
has joined #pact-js

lemitrou
2021-02-15 14:20
has joined #pact-js

helloraj
2021-02-16 08:09
has joined #pact-js

jamesmlucas
2021-02-16 19:29
has joined #pact-js

gabe707
2021-02-16 20:31
has joined #pact-js

wangpei9679
2021-02-16 21:29
has joined #pact-js

wangpei9679
2021-02-16 21:34
Hi guys, I am a starter on Pact. Recently I am trying to setup the contract testing. I try to verify the specific tags of consumer, but it seems that it didn't work as my expected. I put the ` consumerVersionSelectors: [ { tag: 'a', latest: true }, { tag: 'b', latest: true }, { tag: 'c', latest: true }, { tag: 'xxxxontract_testing_setup', latest: true } ]` into the verifierOptions. but it still verified all version of HEAD like the screenshot. what I am expected is that it only verify the latest version of tag `xxxontract_testing_setup`

wangpei9679
2021-02-16 21:37
@tjones

tjones
2021-02-16 22:44
Hmm. At a glance, your tags look right to me, but I don?t tend to use a complex tag set up. Might be worth asking in #pact-broker

wangpei9679
2021-02-16 22:52
Cool, thanks Tim, I used the branch name as tag when I am in my feature branch.

matt.fellows
2021-02-16 23:00
Is the contract the same though? Because if it is, the verification result will apply to _all_ of the contracts with the same content

matt.fellows
2021-02-16 23:01
i.e. if you make 4 separate publishes and give them different tags, but the content is the same. The verification result for *any* of the versions will apply to *all* of the versions

geir
2021-02-16 23:03
has joined #pact-js

wangpei9679
2021-02-16 23:19
Thanks @matt.fellows Oh? yes. the contract content are totally same. Does pact broker use checksum to check if the content are same?

abubics
2021-02-16 23:47
I think that implementation detail is irrelevant, but implicitly yes, if the content is the same, then a hash or checksum would also be the same :)

matt.fellows
2021-02-17 00:03
What @abubics said

matt195
2021-02-17 00:35
This was it, thanks @matt.fellows!

matt195
2021-02-17 00:36
It turns out that mocha behaves surprisingly when an `afterEach` hook fails. Instead of just failing that example, it skips all the other examples in that suite.

tjones
2021-02-17 00:37
That is surprising!

tjones
2021-02-17 01:21
This is actually a really helpful feature that avoids the need to do unnecessary re-validation

tjones
2021-02-17 01:22
There are some diagrams you might find useful here: https://docs.pact.io/getting_started/versioning_in_the_pact_broker/

soruma.net
2021-02-17 05:58
has joined #pact-js

victoria.kruczek
2021-02-17 08:26
hey guys! That?s probably a silly question, but can I log out interaction which has already been added to the mock server? If so, I need a tip on how to do it. When I print out `provider.mockService.interaction` it gives me back `undefined`, so: A. I?m running the wrong command to print out the interaction B. My interaction is not being added :sweat_smile:

tjones
2021-02-17 08:26
It?s possible, although the pact log already contains this information

tjones
2021-02-17 08:27
What are you trying to do? We can probably help with the direct problem you?re trying to get this info to solve

victoria.kruczek
2021-02-17 08:29
Ohhh, ok, so if my metadata is equal to null in the pact log it means the interaction is not registered? :thinking_face: ``` "description": "a request for all clients", "providerState": "i have a list of clients", "request": { "method": "GET", "path": "/api/submissions?filter=[{year: 2000, \"countryCode\":\"PL\"}]"]", "headers": { "Accept": "application/json, text/plain, */*" } }, "response": { "status": 200, "headers": { }, "body": [ { "state": 9 } ] }, "metadata": null }```

tjones
2021-02-17 08:29
The request and the response are there

tjones
2021-02-17 08:30
you should see a line like: `Registered expected interaction GET /api/xxxxxx`

tjones
2021-02-17 08:30
Although, that path looks weird in your example

victoria.kruczek
2021-02-17 08:31
Oh ok, so my function in the unit tests section is not outputting anything, correct? And therefore it didn?t get logged by the pact?

tjones
2021-02-17 08:32
I?m not sure what you mean. Could you share your test code?

tjones
2021-02-17 08:33
Pact will log when it registers an interaction, when it receives the request from your consumer, and whether that request matched the registered interaction

victoria.kruczek
2021-02-17 08:34
``` it('empty array', async () => { Submission.getAll.mockImplementationOnce(() => Promise.resolve({ data: [], }), ); const result = await submissions.getAllSubmissions('123', 123, 2000, 'PL'); expect(result).toEqual([]); });```

tjones
2021-02-17 08:35
I don?t see where you?re setting up pact in that example

tjones
2021-02-17 08:35
usually in a pact consumer test, there wouldn?t be any mocks

tjones
2021-02-17 08:35
unless you have an unusual scenario

victoria.kruczek
2021-02-17 08:37
what that unusual scenario could be? Also, why wouldn?t be there any mocks? I think I might have missed something fundamental here

tjones
2021-02-17 08:37
In a pact test, pact does the mocking for you


tjones
2021-02-17 08:37
^ There are some diagrams here that might help

tjones
2021-02-17 08:37
This one in particular

tjones
2021-02-17 08:38
A pact consumer test will have your actual client code sending an actual request to the mock provider that Pact sets up for you.

victoria.kruczek
2021-02-17 08:40
ok, I have forgotten about that in the heat of trying to make it run. Let me approach this once more time, thank you a lot!

tjones
2021-02-17 08:40
You?re welcome. Good luck!

vikrant.sarkaniya
2021-02-17 08:41
Hi All, I am new to pact and contract testing, I want to create a consumer and provider test for my existing API's , Can anyone help me with how I could setup this?

tjones
2021-02-17 08:42
There are several examples in the repository here: https://github.com/pact-foundation/pact-js/tree/master/examples

tjones
2021-02-17 08:42
the e2e test is a good starting point - both the consumer and the provider are in the same project, but other than that it shows what a normal pact flow would look like

tjones
2021-02-17 08:43
If you are new to pact, I would start here: https://docs.pact.io/getting_started/how_pact_works

matt.fellows
2021-02-17 09:11
also howtolearn has a number of good tutorials/workshops

2021-02-17 09:11
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-02-17 09:12
also these (even simpler) starting points: https://docs.pactflow.io/docs/tutorials/

matt.fellows
2021-02-17 09:12
note to self: add these to OSS docs!

vikrant.sarkaniya
2021-02-17 09:41
I tried creating the Consumer test but getting below error:

vikrant.sarkaniya
2021-02-17 09:41
1) Favorites API test get favorites by filter: AssertionError: expected { Object (TargetId, Created, ...) } to deeply equal { Object (TargetId, Created, ...) } + expected - actual { - "Created": [undefined] - "TargetId": [undefined] - "TargetObjectType": [undefined] - "UserId": [undefined]

matt.fellows
2021-02-17 09:42
Hi Vikrant, worth also reading howtoask

2021-02-17 09:42
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help

matt.fellows
2021-02-17 09:43
it?s going to be hard for us to help you without the input code that?s getting us to that output

matt.fellows
2021-02-17 09:43
This looks like a non Pact assertion also (Jest? Mocha?)

matt.fellows
2021-02-17 09:44
So my guess is that your test is doing some assertions on the API response from the mock service, which is not configured to respond with the payload you want (hence the `undefined`

vikrant.sarkaniya
2021-02-17 09:52
:<//favorites.services.dev.corp.lego.com/api/v1>' }); describe('Favorites API test', () => { // (3) Setup Pact lifecycle hooks before(() => mockProvider.setup()); afterEach(() => mockProvider.verify()); after(() => mockProvider.finalize()); it('get favorites by filter', async () => { // (4) Arrange const expectedfavorites = {Result:[{ TargetId: '20da7438-1382-4b80-b447-6da61f34e719', Created:'2021-02-15T12:11:59+00:00', TargetObjectType: 'Application', UserId: 'b1a660d2-f23b-4f52-b04d-dc4bc8546e0e'}]}

vikrant.sarkaniya
2021-02-17 09:52
this Is what I wrote in my consumer.pact.js file

matt.fellows
2021-02-17 09:53
looks familiar :stuck_out_tongue:

matt.fellows
2021-02-17 11:24
you seemed to have truncated the file, so now it?s a little harder to debug for you

matt.fellows
2021-02-17 11:25
I?d recommend dumping the response body via a `console.log` in your api client class to see what structure is coming back - that will help

matt.fellows
2021-02-17 11:25
also `trace` level logging will print that out for you too

therimpact
2021-02-17 12:30
has joined #pact-js

amaljayaraj07
2021-02-17 13:13
Hello All, I have a question on how can we manage running the provider tests when we have a `term` matcher in the API path? the below is the sample interaction using `pact-js` ```const uuid = '497f6eca-6276-4993-bfeb-53cbbbba6f08' const interaction = new Interaction() .given('an asset exists') .uponReceiving('a request to return an asset') .withRequest({ method: 'GET', path: term({ generate: `/assets/${uuid}`, matcher: '/assets/[\\w]{8}(-[\\w]{4}){3}-[\\w]{12}', }), }) .willRespondWith({ status: 200, body: like({ id: uuid, name: 'foo-bar', }), }) await provider.addInteraction(interaction)``` For the above example how can we run the provider test and make it work? Does the provider always have to create an asset entry with the hardcoded `uuid` defined in the interaction? Or can we actually have a flexible way of using the provider state where any asset with an `uuid` is good enough in the provider database to pass the test?

christopher.roberts
2021-02-17 14:06
Has anyone seen the following issue? ``` FAIL test/src/Health.pact.test.js (157 s) Pact between soa_translate_service and soa_translate_service with 30000 ms timeout for Pact × encountered a declaration exception (2 ms) ? Pact between soa_translate_service and soa_translate_service ? with 30000 ms timeout for Pact ? encountered a declaration exception TypeError: Cannot read property 'logLevel' of undefined 6 | const { Matchers } = require("@pact-foundation/pact"); 7 | > 8 | pactWith( | ^ 9 | { 10 | consumer: process.env.CI_PROJECT_NAME, 11 | provider: process.env.CI_PROJECT_NAME, at new Pact (node_modules/@pact-foundation/pact/src/httpPact.ts:59:20) at setupProvider (node_modules/jest-pact/index.js:23:20) at Suite.<anonymous> (node_modules/jest-pact/index.js:57:15) at jestPactWrapper (node_modules/jest-pact/index.js:37:5) at Suite.<anonymous> (node_modules/jest-pact/index.js:64:67) at Object.<anonymous>.exports.pactWith (node_modules/jest-pact/index.js:64:12) at Object.<anonymous> (test/src/Health.pact.test.js:8:1) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 157.472 s Ran all test suites.``` I debugged it and the code is never initializing the "serviceFactory" variable in httpPact.ts. Does anyone know how this variable should be initialized?

brendan.donegan
2021-02-17 14:09
What you seem to want is fromProviderState, which is a new feature in Pact v3. I am also looking to use this and your use case seems to be identical


christopher.roberts
2021-02-17 14:13
I think it might have something to do with the fact that I'm loading this class as typescript instead of javascript

amaljayaraj07
2021-02-17 15:07
Yes, you are right, V3 feature should solve this. In my case my provider is going to use pact .net and as far I know the .net library is not catching up with v3. It will be nice to know if there are some other work arounds which could work without the v3 spec.

christopher.roberts
2021-02-17 15:26
related question: does jest-pact have a cache and if so how can I clear it?

brendan.donegan
2021-02-17 16:00
@amaljayaraj07oh? you know this channel is pact-js right :slightly_smiling_face: ?

brendan.donegan
2021-02-17 16:01
ah, the *provider* is pact .net

amaljayaraj07
2021-02-17 16:21
Yeah.. The provider is unfortunately .net :expressionless: so I am looking for common appproch.

brendan.donegan
2021-02-17 16:28
Pact v2 doesn?t support this concept at all unfortunately (afaik)

brendan.donegan
2021-02-17 16:29
one thing i would say is i don?t know if there?s actually a rule that says you need to do the Pact verification in the same language as the provider

amaljayaraj07
2021-02-17 16:42
Hmm.. That's interesting.. But if we want to setup provider states and if we don't use the same language/framework as the provider, one would have to do quite a bit of coding to write utility methods in the other language to create test data in the provider. Then the whole thing becomes way too complicated. But this is an interesting idea though :slightly_smiling_face:

brendan.donegan
2021-02-17 16:45
It?s certainly best practice to use the same language

andrzej.igielski
2021-02-17 21:41
has joined #pact-js

matt.fellows
2021-02-17 23:22
usually when you get a ?cannot read property ?xxx? of undefined? it means the underlying object/class instance has disappeared or not been initialised. But I don?t know Pact Jest well enough to have a stab at guessing why that might be the case

matt.fellows
2021-02-17 23:22
`logLevel` is something on the underlying Pact object, I?m guessing, so it perhaps wasn?t able to construct the Pact class properly

matt.fellows
2021-02-17 23:22
so when trying to set the log level, it failed

matt.fellows
2021-02-17 23:23
AH, I missed you last statement about `serviceFactory`

matt.fellows
2021-02-17 23:23
short answer from me is no

matt.fellows
2021-02-17 23:23
But @tjones or @yousafn might know

tjones
2021-02-17 23:35
This is a general pact-js problem- it happens when the mock server fails to start up. You probably have a log line further up telling you what went wrong. We should check this case and emit a more helpful error

tjones
2021-02-17 23:37
I?d be surprised if there?s a bug causing this- I?ll have a look at the code when I?m at my desk

christopher.roberts
2021-02-17 23:39
I figured it out. I had a jest moduleNameMapper regex in the wrong order :)

tjones
2021-02-18 01:30
Ah, right. Looking at the code, I guess you were accidentally stubbing pact-node

mikewagner21
2021-02-18 03:15
has joined #pact-js

tjones
2021-02-18 05:22
You could use the `providerStateChangeUrl` to do provider verification in a different language

tjones
2021-02-18 05:23
To do this, you need to spin up your provider with an extra endpoint that handles pact state information. You want to be able to only spin up this endpoint during provider verification

tjones
2021-02-18 05:26
If you are restricted to v2 pacts, an alternative approach is to use a specific example path (this is what I do). Eg, in your case, I would say something like: ``` const interaction = new Interaction() .given('asset "b6bf9b18-71a9-11eb-9439-0242ac130002" exists') .uponReceiving('a request to return an asset') .withRequest({ method: 'GET', path: '/assets/b6bf9b18-71a9-11eb-9439-0242ac130002', }) ```

tjones
2021-02-18 05:26
Remember that a contract isn?t the same as a spec - you don?t need to describe all possible responses.

tjones
2021-02-18 05:29
Good answers above, @brendan.donegan! :taco:

francis.lobo
2021-02-18 05:51
Hello folks I am new to Pact and Typescript/javascript I need some help with Pact JS.. Question in thread..

francis.lobo
2021-02-18 05:51
I am trying to generate contracts with the following pattern (stripped down code) ``` export interface SuccessResponse<T> extends BaseResponse { data: T; } export interface returnObj { id: number; name: string tags: { tagId: string; }[]; } const successResponse:SuccessResponse<returnObj> = { data:Matchers.eachLike( { id : Matchers.decimal, name : Matchers.string, tags: [] } ,{min : 0}) } ``` In the generated Pact, I only see matchers for the `tags` field. ``` "body": { "message": { "data": [ { "tags": [ ], } ] } } "matchingRules": { "$.body.message.data": { "min": 1 }, "$.body.message.data[*].*": { "match": "type" }, }``` I am a bit stuck on how to get the matchers for all the other fields.. When using Pact JVM, I tried something like ```DslPart body = new PactDslJsonBody(); body.minArrayLike("data", 1) .stringType("id") .stringType("name") .....``` and I see all the necessary json fields and matchers in the PACT file What am I missing in Pact-JS?

matt.fellows
2021-02-18 05:55
`Matchers.decimal` is a function, not a value

matt.fellows
2021-02-18 05:56
so the value of `id` is literally a JS function, which is not going to be serialisable

matt.fellows
2021-02-18 05:56
so the fix should be easy

matt.fellows
2021-02-18 05:56
```id: Matchers.decimal(42.0)```

matt.fellows
2021-02-18 05:56
```name: Matchers.string("example string")```

matt.fellows
2021-02-18 06:10
that help?

tjones
2021-02-18 07:21
This is a common question, so I?ve opened https://github.com/pact-foundation/pact-js/issues/611 to make the tooling more helpful

vikrant.sarkaniya
2021-02-18 07:41
I was able to successfully run the consumer test But I am stuck with the provider test now.

vikrant.sarkaniya
2021-02-18 07:41
I want to run my actual API against the pact created by consumer test

vikrant.sarkaniya
2021-02-18 07:42
and the API call takes authorization token from another endpoint


khandelwalbhushan
2021-02-18 08:10
has joined #pact-js

matt.fellows
2021-02-18 08:10
You have a few choices in Pact JS 1. Remove auth from the provider pact test context 2. Stub authorization in your API verification (what I normally do, because it?s an external system, and I don?t want a dependency on that in my unit tests) 3. Use request filters, to dynamically replace the credentials with real ones (this is OK if the auth is internal to the service, but generally not a good idea for externalised auth)

aniket.agarwal
2021-02-18 09:21
has joined #pact-js

brendan.donegan
2021-02-18 09:32
ah darn, i just ate breakfast :smile:

brendan.donegan
2021-02-18 09:33
_puts taco aside for lunch_

arpit.modani
2021-02-18 09:43
has joined #pact-js

byronth
2021-02-18 11:45
has joined #pact-js

victoria.kruczek
2021-02-18 14:51
Hello! I?m writing because I?ve encountered an issue with CORS when creating a consumer pact. I?m applying Pact?s to a mobile app and cors is preventing me from properly hitting the desired GET request: ``` Missing requests: GET /api/submissions Unexpected requests: OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]&``` I?m using pact-jest and I?ve setup a `cors: false` parameter, although it didn?t help. We also have some of the ports whitelisted, so they in theory don?t use the cors, but they didn?t do trick either. Here is the log from Pact: ```I, [2021-02-18T15:44:48.700696 #33601] INFO -- : Received request OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& D, [2021-02-18T15:44:48.700850 #33601] DEBUG -- : { "path": "/api/submissions", "query": "filter=[%7B%22id%22:13548%7D]&", "method": "options", "headers": { "Origin": "http://localhost", "Access-Control-Request-Method": "GET", "Access-Control-Request-Headers": "Authorization", "User-Agent": "Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/16.2.2", "Host": "localhost:1234", "Connection": "keep-alive", "Version": "HTTP/1.1" } } E, [2021-02-18T15:44:48.701346 #33601] ERROR -- : No matching interaction found for OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& E, [2021-02-18T15:44:48.701428 #33601] ERROR -- : Interaction diffs for that route: E, [2021-02-18T15:44:48.701448 #33601] ERROR -- : W, [2021-02-18T15:44:48.718456 #33601] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api/submissions Unexpected requests: OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& W, [2021-02-18T15:44:48.718517 #33601] WARN -- : Missing requests: GET /api/submissions Unexpected requests: OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& I, [2021-02-18T15:44:48.733870 #33601] INFO -- : Cleared interactions``` Any tips/trick how to deal with this? :thinking_face:

tjones
2021-02-18 16:18
You probably want `cors: true`. It looks like your client is sending the cors requests, but the mock server is not expecting them. Also, it looks like your request is sending a query, but the interaction isn?t expecting it

francis.lobo
2021-02-18 20:20
Thanks heaps for the reply @matt.fellows That worked! Now I can see the correct matchers in my pact file :slightly_smiling_face:

isa.levine
2021-02-18 23:37
has joined #pact-js

victoria.kruczek
2021-02-19 08:50
@tjones Do you mean the `filter=[%7B%22id%22:13548%7D]&` query? It?s added automatically when fetching the CORS. It?s also added now to the GET request (after setting `cors: true`), not sure why. The api/submissions doesn?t accept such query :thinking_face: I?m totally lost here

tjones
2021-02-19 09:13
CORS is an http thing, usually handled by the http library/ server/ api gateway. It usually isn?t explicit in the server code (maybe in the config). Wikipedia has some fairly clear explanations if you want to learn more.

victoria.kruczek
2021-02-19 09:14
Ok, I will dig into, thank you :slightly_smiling_face:

victoria.kruczek
2021-02-19 09:18
I also found this: https://github.com/pact-foundation/pact-mock_service/wiki/Using-the-mock-service-with-CORS, sorry that I bothered you when it?s out there :facepalm: It was in a heat of the moment, have to admit that :sweat_smile:

brian.pfretzschner
2021-02-19 10:15
has joined #pact-js

neild
2021-02-19 14:34
I?m not able to modify `req.query` in the `requestFilter` function I?ve defined in my provider verification tests. Is this expected behavior or a bug? Ex/ ```const opts = { ...options requestFilter: async (req, res, next) => { req.query.foo = 'bar'; next(); }, } const verifier = new Verifier(opts)``` ```// middleware app.use((req, res, next) => { console.log('FOO', req.query.foo); // undefined next(); });``` If this is a bug, will open an issue in github with a reproducible demo. Wanted to confirm here whether this is a bug or not before I do that.

brendan.donegan
2021-02-19 14:47
i think this is a feature, based on the behavior in pact-jvm

neild
2021-02-19 21:33
Will look at the pact-jvm docs. Thank you!

sagupta
2021-02-19 21:53
Hello ppl, I am setting up a test for consumer and i use jest to run the tests. I have added `"@pact-foundation/pact": "^9.15.0"` dependency . I am however getting this error when running the test . Am i missing some configuration to set in jest ? ```SyntaxError: /Users/<>/<>/graphql/package.json: Unexpected token, expected ";" (2:11) 1 | { > 2 | "private": true, | ^ 3 | "name": "graphql", 4 | "version": "0.0.0", 5 | "author": "<>", at Parser._raise (node_modules/@babel/parser/src/parser/location.js:241:45) at Parser.raiseWithData (node_modules/@babel/parser/src/parser/location.js:236:17) at Parser.raise (node_modules/@babel/parser/src/parser/location.js:220:17) at Parser.unexpected (node_modules/@babel/parser/src/parser/util.js:149:16) at Parser.semicolon (node_modules/@babel/parser/src/parser/util.js:122:40)```

matt.fellows
2021-02-19 22:08
I saw this recently actually, there's a problem with the jest/babel setup. Remove plugins until you work out which one

matt.fellows
2021-02-19 22:08
I'd like to get to the bottom of it, please share which one as it might be something we can guard against

sagupta
2021-02-19 22:15
I only have one plugin , this is what the `babel.config.js` looks ```module.exports = { presets: [ [ '@babel/env', { targets: { node: 'current', }, }, ], ], plugins: [ '@babel/plugin-proposal-optional-chaining', ], };```

sagupta
2021-02-19 22:16
and this is my `jest.config.js` ```module.exports = { collectCoverageFrom: ["packages/*/src/**/*.js"], coverageDirectory: "test-results/jest/coverage", reporters: [ "default", ["jest-junit", { outputDirectory: "test-results/jest" }], ], restoreMocks: true, setupFiles: ["<rootDir>/jest.setup.js"], testEnvironment: "node", transform: { "^.+\\.gql$": "<rootDir>/transform-gql.js", ".*": "babel-jest", }, runner: "groups", };```

sagupta
2021-02-19 22:18
removing that plugin doesnt solve it

matt.fellows
2021-02-19 22:22
Look at the transform regex, it's going to transform all files

matt.fellows
2021-02-19 22:22
That would include JSON which seems unlikely what you want

matt.fellows
2021-02-19 22:26
There may be an issue with it. It theory you should be able to modify anything but I think it actually only allows headers. There is definitely a known issue with body

sagupta
2021-02-19 22:26
I added this to ignore package.json ```transformIgnorePatterns: ['package.json'],```

sagupta
2021-02-19 22:27
When i run the tests now , I get this error ```Test suite failed to run SyntaxError: Unexpected token ; in JSON at position 12 at JSON.parse (<anonymous>) at Runtime._loadModule (node_modules/jest-runtime/build/index.js:568:59) at Object.<anonymous> (node_modules/psl/index.js:14:19) at Object.<anonymous> (node_modules/request/node_modules/tough-cookie/lib/pubsuffix-psl.js:32:11)```

matt.fellows
2021-02-19 22:35
I can't you this way I'm afraid, there are just too many variables that I can't guess in advance

matt.fellows
2021-02-19 22:35
You're going to need to create a minimal project and go from there

matt.fellows
2021-02-19 22:35
I've just found the comms I had with anither customer that had the issue. It was the transform picking up too many files

matt.fellows
2021-02-19 22:36
So ignoring just package.json may not be enough

matt.fellows
2021-02-19 22:36
You should make sure it only transforms JS files

tjones
2021-02-20 02:29
I agree, this looks like a babel/jest configuration issue rather than a pact issue.

tjones
2021-02-20 02:30
Are you using a particular pact example as a base? Perhaps we have the wrong settings in it

chitra.adikesavan
2021-02-20 15:50
has joined #pact-js

andrzej.igielski
2021-02-20 19:28
@andrzej.igielski has left the channel

francis.lobo
2021-02-21 23:56
Hello folks! A quick question on the roadmap. Is there an ETA for Pact V3 support on Pact JS? I understand it is on beta on a feature flag now. is there any plan to get it on master?

tjones
2021-02-21 23:57
We?re talking about that at the moment. No specific ETA, I am afraid.

francis.lobo
2021-02-21 23:57
Thanks for the update @tjones :slightly_smiling_face:

tjones
2021-02-22 00:00
We are *extremely* keen to get V3 support in to master. I?d ideally like to do it with as few breaking changes as possible.

artur
2021-02-22 03:57
@francis.lobo we are using the beta for https://github.com/owncloud/owncloud-sdk it mostly works pretty well

francis.lobo
2021-02-22 04:39
That sounds good :slightly_smiling_face: Waiting for it

francis.lobo
2021-02-22 04:41
Following up on that, If I have some consumer tests coming from Pact JVM with PactV3 and some from Pact JS and my Provider tests are in Pact JVM Do you foresee any issues with such a setup?

francis.lobo
2021-02-22 04:41
Thanks for the info @artur :+1:

tjones
2021-02-22 04:42
No, that should be fine :+1:

francis.lobo
2021-02-22 04:42
Sweet! thanks @tjones

tjones
2021-02-22 04:43
To confirm, you have: V2 pacts from pact-js V3 pacts from pact-jvm V2+3 verification in pact-jvm ?

francis.lobo
2021-02-22 04:47
Yes that's where we are moving. right now we have everything in JVM, adding a JS consumer

tausif2909
2021-02-22 06:13
Hi, How to pass value for `pathFromProviderSide` in nodeJS code in provider verification code? Can anyone share the example?

ankita.soni
2021-02-22 07:26
has joined #pact-js

jacek.helper
2021-02-22 08:03
has joined #pact-js

sagupta
2021-02-22 08:12
alright, i can check today with one of the devs about the transform. Will keep you posted here if that solves it

sagupta
2021-02-22 08:42
the problem was indeed with transform in `jest.config.js` Changing transform to ```transform: { '^.+\\.gql$': '<rootDir>/transform-gql.js', '^.+\\.(js|jsx)$': 'babel-jest', },``` did the trick :slightly_smiling_face: :thumbsup:

matt.fellows
2021-02-22 09:01
Thanks for confirming!

seanw122
2021-02-22 15:36
has joined #pact-js

akennedy
2021-02-22 15:54
has joined #pact-js

esimpson
2021-02-22 16:42
has joined #pact-js

neild
2021-02-22 17:02
I see. Thank you for the response. I figured out a workaround

dagrawal
2021-02-22 17:24
has joined #pact-js

venkata.pro
2021-02-22 21:47
has joined #pact-js

matt.fellows
2021-02-22 22:55
What did you do?

ashish.joshi
2021-02-23 00:32
Hey @matt.fellows Able to resolve authorization issues, but still stuck with second half, We tried to use `nock` but failed while testing locally, since my docker-run and test-run are different process and `nock` does not work on different process. Can you share me some JS example which you mentioned you have worked on before with this type of situation where before verifying the pact the provider service communicate with other service to get some data which is essential for response to consumer request(triggered from mock server).

matt.fellows
2021-02-23 00:37
is your provider running in docker? If so, you?re going to need to find a way to stub out the downstream endpoints for docke

matt.fellows
2021-02-23 00:38
one option is to use tools like docker compose, that startup sidecar services for each backend service with stub APIs. I usually configured endpoitns through environment variables, so this means you can replace downstream systems without actually changing any provider code

ashish.joshi
2021-02-23 00:47
Because i don't want to complicate things, since i have 5-6 other services which my provider will communicate before responding back to consumer's request and i have to run 5-6 docker images while running this test. is there any other option, like will `pact-stub-server` work in this case?

matt.fellows
2021-02-23 00:48
You could run the stub server, of course

matt.fellows
2021-02-23 00:50
You can?t stub the provider endpoints from the outside using your test code that doesn?t have access to it.

matt.fellows
2021-02-23 00:51
so you only have a few options: 1. Update your setup such that the provider doesn?t talk to real endpoints (e.g. stub server) 2. Update the provider code that runs in that docker container, stubbing out with code the endpoints

ashish.joshi
2021-02-23 00:54
Ok we'll try option 1 for now, do you have any real time example of using `stub-server` i tried to find it, but just got the documentations on commands to use it not a real time implementation.

matt.fellows
2021-02-23 00:55
I?m not sure what you mean, sorry?

ashish.joshi
2021-02-23 00:57
Sorry, my bad i didn't explain it properly. Do you have any real life example of using `pact-stub-server` like how we have pact-js workshop examples?

francislainy.campos
2021-02-23 08:52
Hi, good morning. I?m getting this error here trying to implement pact and jest and I?m not sure what I could be doing wrong. `Cannot read property 'addInteraction' of undefined`

francislainy.campos
2021-02-23 08:53
```import { Pact } from '@pact-foundation/pact'; import path from 'path'; import { getOwners } from '../../apis/ids'; describe('Clients Service', () => { const provider = new Pact({ consumer: 'FrontendWebsite', provider: 'ProductService', log: path.resolve(process.cwd(), 'logs', 'pact.log'), logLevel: 'warn', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, { firstName: 'Wonder', lastName: 'Woman', age: 30, id: 2, }, { firstName: 'Homer', lastName: 'Simpson', age: 39, id: 3, }, ]; afterEach(() => provider.verify()); describe('GET Clients', () => { beforeEach(() => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/view/states', headers: { Accept: 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; return provider.addInteraction(interaction); }); test('returns correct body, header and statusCode', async () => { const response = await getOwners(); expect(response.headers['content-type']).toBe( 'application/json; charset=utf-8', ); expect(response.data).toEqual(GET_EXPECTED_BODY); expect(response.status).toEqual(200); }); }); });```

francislainy.campos
2021-02-23 08:54
```export const getOwners = async () => { return Promise.resolve({ json: () => Promise.resolve(mockOwners), }); };```

francislainy.campos
2021-02-23 08:54
Many thanks.

brendan.donegan
2021-02-23 09:11
@francislainy.campos we have a template for Jest Pact in the Lift codebase, you can use that

francislainy.campos
2021-02-23 09:12
Thanks Brendan, that one does not allow me to run the tests individually through the IntelliJ run button.

brendan.donegan
2021-02-23 09:13
For the benefit of the group, it looks like this: ```import { Matchers } from '@pact-foundation/pact'; import { pactWith } from 'jest-pact'; ... (import your API code and set up any other data) pactWith( { consumer: '<your consumer>', provider: '<your provider>', cors: true, pactfileWriteMode: 'merge', }, provider => { describe('The query you are making', () => { beforeEach(() => { await provider.addInteraction( // You should pass an object describing the expected request and response per the Pact JS documentation ); }); it('returns the correct response', async () => { // call your API and get the response // provider.mockService.baseUrl contains the hostname and // port the mock provider is running on // // assert some things about the response }); }); }, );```

francislainy.campos
2021-02-23 09:14
I?d like to be able to do this

brendan.donegan
2021-02-23 09:15
I think the way jest-pact works may break the Jest plugin for Intellij

brendan.donegan
2021-02-23 09:15
If you really want to use it you may have to use raw jest

brendan.donegan
2021-02-23 09:15
ahh, you aren?t using jest-pact, gotcha

brendan.donegan
2021-02-23 09:16
I didn?t notice that

francislainy.campos
2021-02-23 09:18
Yes, I?m trying to make this piece work, which I found on a tutorial on the internet, as this one would allow me to run the tests individually this way.

brendan.donegan
2021-02-23 09:19
I think the issue is you created the provider inside the other describe block

francislainy.campos
2021-02-23 09:20
I tried variations of this

francislainy.campos
2021-02-23 09:20
```import { Pact } from '@pact-foundation/pact'; import path from 'path'; import { getOwners } from '../../apis/ids'; const provider = new Pact({ consumer: 'FrontendWebsite', provider: 'ProductService', log: path.resolve(process.cwd(), 'logs', 'pact.log'), logLevel: 'warn', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, }); describe('Clients Service', () => { const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, { firstName: 'Wonder', lastName: 'Woman', age: 30, id: 2, }, { firstName: 'Homer', lastName: 'Simpson', age: 39, id: 3, }, ]; afterEach(() => provider.verify()); describe('GET Clients', () => { beforeEach(() => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/', headers: { Accept: 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; return provider.addInteraction(interaction); }); test('returns correct body, header and statusCode', async () => { const response = await getOwners(); expect(response.headers['content-type']).toBe( 'application/json; charset=utf-8', ); expect(response.data).toEqual(GET_EXPECTED_BODY); expect(response.status).toEqual(200); }); }); });```

brendan.donegan
2021-02-23 09:20
Personally I think the amount of extra code and possibility for mistakes with raw jest is not worth being able to run it through the UI, but lets see if we can make it work

francislainy.campos
2021-02-23 09:21
Thanks

brendan.donegan
2021-02-23 09:21
Let me see if I can dig something out. There?s also the issue that there are Promises involved here

brendan.donegan
2021-02-23 09:22
you?ll notice in my example, addInteraction is await?ed

francislainy.campos
2021-02-23 09:22
I used the mock promise just to try to see if it would make any difference this way

francislainy.campos
2021-02-23 09:22
But we?ll be using calls of this type instead

francislainy.campos
2021-02-23 09:22
```export const getStudents = async ({ schoolId }) => { const url = `${config.idsBaseUri}/ids/v1/schools/${schoolId}/students`; return fetch(url, { headers, }); };```

francislainy.campos
2021-02-23 09:24
Yeah, I tried to implement that but got lost on the syntax for this on my code since the interaction is being added and returned at the same time.


francislainy.campos
2021-02-23 09:25
This is where I?m getting the sample from

brendan.donegan
2021-02-23 09:29
okay, i remember now

brendan.donegan
2021-02-23 09:29
unfortunately that example is completely wrong

francislainy.campos
2021-02-23 10:06
Changed it a bit and removed the mocking api to use the real server call and I think it?s a bit closer now but with a different error, probably something on the path for the request, which I?m trying to figure out what would be the correct one here. ```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll((done) => { provider.setup().then(() => done()); }); afterAll((done) => { provider.finalize().then(() => done()); }); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/', headers: { Accept: 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.headers['content-type']).toBe( 'application/json; charset=utf-8', ); expect(response.data).toEqual(GET_EXPECTED_BODY); expect(response.status).toEqual(200); }); });```

matt.fellows
2021-02-23 10:15
In that last error you show, it is complaining about a ?local issuer certificate?

matt.fellows
2021-02-23 10:16
that would indicate you?re trying to talk to an https service somewhere - have you modified your provider to not talk https, and instead just talk to the mock service?

matt.fellows
2021-02-23 10:16
That could explain both a) why the ?missing request? is there and b) why that error is shown (i.e. you?re code is trying to talk to another place, over https)

brendan.donegan
2021-02-23 10:16
:point_up:

francislainy.campos
2021-02-23 10:16
Hi Matt, I haven?t changed my provider no, it?s the same our application talks to but we don?t own the code for it.

matt.fellows
2021-02-23 10:17
not the provider, but the api client that talks to the provider

matt.fellows
2021-02-23 10:17
(or would to, in a non-pact context)

francislainy.campos
2021-02-23 10:17
```export const getStates = async () => { const url = `${config.idsBaseUri}/ids/v1/states`; return fetch(url, { headers, }); };```

matt.fellows
2021-02-23 10:17
in your code, that is whatever `getStates()` is

brendan.donegan
2021-02-23 10:17
@francislainy.campos the function getStates doesn?t send the request to the mock provider

matt.fellows
2021-02-23 10:18
right, so `config.idsBaseUri` needs to be configurable, and needs to be configured to talk to the mock provider from Pact

brendan.donegan
2021-02-23 10:18
it?s sending it to IDS

brendan.donegan
2021-02-23 10:18
(IDS is one of our providers)

matt.fellows
2021-02-23 10:18
``` beforeAll((done) => { provider.setup().then((config) => /* config contains the details of the dynamic mock service, use this to configure the api client */); });```

matt.fellows
2021-02-23 10:19
also, you don?t need done anymore

brendan.donegan
2021-02-23 10:19
@matt.fellows yeah, can you advice on using done :smile: I found it was necessary last year

matt.fellows
2021-02-23 10:20
``` afterAll((done) => { provider.finalize().then(() => done()); }); can be simply: afterAll(() => provider.finalize());```

brendan.donegan
2021-02-23 10:20
oh that?s good, makes it much simpler

brendan.donegan
2021-02-23 10:20
tbh we switched most of our tests to jest-pact and don?t need to worry about any of that :smile:

matt.fellows
2021-02-23 10:20
done is the pre-promise way of saying ?this future thing has finished?. Lots of frameworks still have it for portability

matt.fellows
2021-02-23 10:20
yeah, people keep telling me it?s good :stuck_out_tongue:

francislainy.campos
2021-02-23 11:02
Thank you both. It?s working now.

francislainy.campos
2021-02-23 11:02
```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', port: 3000, }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll((done) => { provider.setup().then((opts) => { process.env.API_PORT = opts.port; done(); }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/ids/v1/states', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.status).toEqual(200); }); });```

francislainy.campos
2021-02-23 11:02
```export const getStates = async () => { const url = `http://localhost:3000/ids/v1/states`; return fetch(url, { headers, }); };```

francislainy.campos
2021-02-23 11:03
I needed to keep `done` on the beforeAll and beforeEach pieces as without it I get that same interaction error as I was initially getting.

matt.fellows
2021-02-23 11:30
``` beforeAll(() => { return provider.setup().then((opts) => { process.env.API_PORT = opts.port; }); });```

matt.fellows
2021-02-23 11:30
that should work just fine

matt.fellows
2021-02-23 11:31
Also, you?ve currently got a hard coded port in Pact anyway (`3000`) so you don?t even need to do it this way. But I?d suggest keeping the dynamic configuration, and dropping the hard coded `port` from your Pact config so Pact will always find an available port - this is helpful on CI, but also locally if you have other things running on that port

matt.fellows
2021-02-23 11:32
glad to hear it?s going!

matt.fellows
2021-02-23 11:33
I don?t have a real life example, but what do you actually want to see in it?

matt.fellows
2021-02-23 11:34
it takes one or more Pact files and becomes a server. You can run it in docker also

francislainy.campos
2021-02-23 11:40
Thanks. Yes, the version of the beforeAll you provided with the return piece works removes the add interaction error. However, I think I may have spoken too soon because I?m now getting a timeout error on my request and the contract is not generating although I don?t remember changing anything else there. If I remove the hardcoded port for the provider piece I then get a 500 instead talking about missing requests.

francislainy.campos
2021-02-23 11:41
```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll((done) => { provider.setup().then((opts) => { process.env.API_PORT = opts.port; done(); }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/ids/v1/states', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.status).toEqual(200); }); });```

francislainy.campos
2021-02-23 11:41
```export const getStates = async () => { const url = `http://localhost:3000/ids/v1/states`; return fetch(url, { headers, }); };```

matt.fellows
2021-02-23 11:42
you didn?t copy my code correctly!

matt.fellows
2021-02-23 11:43
look carefully - because it?s the _most common_ mistake I see people make with javascript and promises

francislainy.campos
2021-02-23 11:43
Owh sorry, no, I pasted the wrong version here

matt.fellows
2021-02-23 11:43
it?s the cause of the timeout, almost certainly

francislainy.campos
2021-02-23 11:43
```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll(() => { return provider.setup().then((opts) => { process.env.API_PORT = opts.port; }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/ids/v1/states', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.status).toEqual(200); }); });```

francislainy.campos
2021-02-23 11:43
This is what I have with the version copied from here.

matt.fellows
2021-02-23 11:43
ok! yes that looks better.

matt.fellows
2021-02-23 11:44
what?s the timeout set to? It could legitimately be taking too long

francislainy.campos
2021-02-23 11:44
It?s localhost though, so why it would take this long?

francislainy.campos
2021-02-23 11:47
But now the error that is coming up the most is the 500 one, with the missing requests.

tjones
2021-02-23 11:48
@brendan.donegan : just catching up on the thread- you mentioned jest-pact breaks a jest IntelliJ plug-in - can you tell me more about this? Maybe we can fix it

francislainy.campos
2021-02-23 11:48
It?s happening regardless of whether I hardcode the port on the provider piece or not.

tjones
2021-02-23 11:48
Also @matt.fellows@matt.fellows@matt.fellows : I want to bring `pactWith` to mocha - maybe next week :)

tjones
2021-02-23 11:49
Also coming this week- `messagePactWith`

francislainy.campos
2021-02-23 11:49
Hi Tim, I think perhaps what Brendan meant was that with the jest-plugin is not possible to use the run button from intellij to run the tests individually.

francislainy.campos
2021-02-23 11:50
That being the reason why I?m trying to refactor our tests and have them work using jest only so I can make use of this functionality.

brendan.donegan
2021-02-23 11:51
@tjones by the way I think you tried to follow up with me about jest-pact with v3, but i can?t find the message now?

tjones
2021-02-23 11:51
There?s a beta version to match

tjones
2021-02-23 11:51
I?ll link you, hold on

brendan.donegan
2021-02-23 11:51
yeah i tried it, and it works

tjones
2021-02-23 11:52
Oh! Awesome, yes. Sorry, I didn?t realise that was you :joy:

tjones
2021-02-23 11:52
Any pain points?

tjones
2021-02-23 11:52
I?m thinking of making it 1.0.0 soon, with a firmer interface.

tjones
2021-02-23 11:53
(since technically anything under 1 can be a breaking change with no notice)

tjones
2021-02-23 11:54
Also, it sounds like you have a lot of specs - I?d be really interested in whether you have any thoughts on this: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-02-23 11:55
(even if those thoughts are ?I wouldn?t use it?)

brendan.donegan
2021-02-23 11:55
yeah, i meant to respond to that. it would be really good for us

tjones
2021-02-23 11:55
Awesome!

francislainy.campos
2021-02-23 11:55
The url looks fine so I?m not sure what could be wrong @matt.fellows?

brendan.donegan
2021-02-23 11:55
it might become slightly less useful soon since we could potentially split our application into multiple consumers :smile:

tjones
2021-02-23 11:55
When we have this, it?ll be easier to do a module that can be given to the `globalSetup` for jest

brendan.donegan
2021-02-23 11:56
but that?s fine

tjones
2021-02-23 11:56
which could clear out your pact directory

tjones
2021-02-23 11:56
At the moment, with jest you have to use `update`, which means that removing interactions doesn?t remove them from your pact file

tjones
2021-02-23 11:57
unless you?re clearing it before each test run (but I suspect most people aren?t, because none of the examples do)

tjones
2021-02-23 11:57
Do you know what it is about jest-pact that causes this?

brendan.donegan
2021-02-23 11:59
i?m really looking forward to jest-pact being released with a stable contract though as i want to switch us over but i?m reluctant to do so if it means refactoring things more than once

brendan.donegan
2021-02-23 11:59
(switch us over to v3)

tjones
2021-02-23 12:01
Have a look in the body. A 500 internal server error is how the mock server tells you that it didn?t receive the interaction you promised

tjones
2021-02-23 12:01
The detailed information will be in the pact log

brendan.donegan
2021-02-23 12:02
@francislainy.campos you?re not using the generated port in the request

tjones
2021-02-23 12:03
Yeah. I think we?ll end up with a different API to the current V3 branch, because I?d like the upgrade pathway from v2 to be very straightforward. But I also don?t want to break things for the current users of the beta.

tjones
2021-02-23 12:03
I?ll be focussing on that a bit next week.

brendan.donegan
2021-02-23 12:03
i was going to say, it would be great if the upgrade path was a bit simpler

brendan.donegan
2021-02-23 12:04
obviously it?s worth breaking the contract to make things better while you have the chance though

tjones
2021-02-23 12:04
Yeah. Some things will naturally change.

tjones
2021-02-23 12:04
It?s also an opportunity to clean up some of the other breaking things that aren?t worth releasing on their own

tjones
2021-02-23 12:05
We can do better typescript types for pact interactions, for example

francislainy.campos
2021-02-23 12:05
Sorry, not really. Just something that I noticed and the reason why I?m trying to move away from it to use the raw jest instead.

tjones
2021-02-23 12:05
there?s a lot of `any` in the api surface that could be narrower

francislainy.campos
2021-02-23 12:05
```I, [2021-02-23T12:03:58.387834 #12739] INFO -- : Registered expected interaction GET /ids/v1/states D, [2021-02-23T12:03:58.387984 #12739] DEBUG -- : { "description": "a request for all clients", "providerState": "i have a list of clients", "request": { "method": "GET", "path": "/ids/v1/states", "headers": { "Accept": "*/*" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "firstName": "Lisa", "lastName": "Simpson", "age": 8, "id": 1 } ] }, "metadata": null } W, [2021-02-23T12:03:58.445679 #12739] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /ids/v1/states W, [2021-02-23T12:03:58.445727 #12739] WARN -- : Missing requests: GET /ids/v1/states I, [2021-02-23T12:03:58.474092 #12739] INFO -- : Cleared interactions```

francislainy.campos
2021-02-23 12:06
This is the whole log

tjones
2021-02-23 12:06
but introducing types where previously there weren?t will be a breaking change for typescript users

tjones
2021-02-23 12:06
Ok. What plugin are you using? I?ll try to reproduce this when I get a chance.

matt.fellows
2021-02-23 12:07
Pretty cut and dry. Your code is not calling the endpoint

matt.fellows
2021-02-23 12:08
Yep, I was just in there before to make a small change

matt.fellows
2021-02-23 12:08
The core native module (currently Rust) doesn?t have types eminating from it, so we?ll need to find a way to add types to that too

matt.fellows
2021-02-23 12:08
more types, is on the whole a good thing though

tjones
2021-02-23 12:09
For that, I think we can just do `.d.ts` files. I?ve done a couple of those recently for other reasons.

matt.fellows
2021-02-23 12:09
yep

tjones
2021-02-23 12:09
(we?re now off the original topic, though)

matt.fellows
2021-02-23 12:10
yes, I?ll exit the thread (I need to sleep I think)(

tjones
2021-02-23 12:11
Note that if you?re using raw jest you?ll need to provide different log file names for each `Pact` instance, otherwise they will clobber each other.

brendan.donegan
2021-02-23 12:18
sorry, i know it?s late for you guys, but one quick question. if i have a provider that is using v3 for verification, will it be able to verify v2 contracts?

matt.fellows
2021-02-23 12:19
yes. The verification process reads the contract, determines the spec, and tests that way

francislainy.campos
2021-02-23 12:30
I don?t use any plugin directly, just out of the box intellij ultimate run configuration for jest.

francislainy.campos
2021-02-23 12:33
Sorry @matt.fellows, for needing a bit of hand holding here but I?m not sure what to do next to have this amended.

francislainy.campos
2021-02-23 13:05
When I right click on any jest test or describe intellij shows me the option to run then, but not for the ones done using jest-pact.

tausif2909
2021-02-23 13:12
I have the call at consumer side `api/assets/{assetId}` where `assetId` is dynamic will be passed from provider side, How do I pass `{assetId}` value from provider side in `nodeJS` project.? can someone share the example ?

tausif2909
2021-02-23 13:16
``` @State("There is a request to get the asset metadata") public HashMap<String, Object> testAssetMetadata() { HashMap<String, Object> map = new HashMap<>(); map.put("assetId", mediaAssetId); return map; }``` I was able to achieve this using hashmap in provider state in `pact-jvm` but not sure how to do the same in `pactJS`

francislainy.campos
2021-02-23 15:10
It?s working now, thanks. We were missing sending the url inside the getStates call

francislainy.campos
2021-02-23 15:10
```test('returns correct body, header and statusCode', async () => { const response = await getStates( `http://localhost:${process.env.API_PORT}/ids/v1/states`, ); expect(response.status).toEqual(200); });```

francislainy.campos
2021-02-23 15:11
```export const getStates = async (url) => { return fetch(url, { headers, }); };```

francislainy.campos
2021-02-23 15:12
Thanks for your guys help. :)

tjones
2021-02-23 15:40
I?ve released `jest-pact` 0.8.3, which now includes `messagePactWith` and also adds `pactWith.only` / `pactWith.skip` (alongside the already existing `fpactWith` and `xpactWith`)

tjones
2021-02-23 15:43
Also, npm says that jest-pact was downloaded 40,341 times in the last week - which is roughly four times a minute. That?s pretty cool.

tjones
2021-02-23 15:48
At the moment, pact-js doesn?t support provider side parameters. We?re working on the next version which will- you can try the beta by following the instructions here: https://github.com/pact-foundation/pact-js#pact-js-v3

tjones
2021-02-23 15:51
Ah. I wonder if that?s because `pactWith` doesn?t look like a `describe` to the plugin. What happens if you wrap the `pactWith` call in a describe? ```describe("pact",() => { pactWith(..... , (provider) =>{....}) })```

francislainy.campos
2021-02-23 15:58
That?s a good idea and it may work with some more thought but I tried it here now quickly and I did get the run button but then a message No tests found once it tried to run the tests.

tjones
2021-02-23 16:04
Hm. That?s very weird. I?ll have to see if I can reproduce it with the CE version (I don?t have Ultimate)

francislainy.campos
2021-02-23 16:05
I?m not sure you can use CE for that, but maybe the trial version for ultimate or webstorm may do?

tjones
2021-02-23 16:08
Glad you got it working! It?s a good idea to only inject the baseURL into the test, otherwise you might not be testing the endpoint that you actually hit in production: ```export const getStates = async (baseUrl) => { return fetch(`${baseUrl}/ids/v1/states`, { headers, }); };``` then in your test: ```test('returns correct body, header and statusCode', async () => { const response = await getStates( `http://localhost:${process.env.API_PORT}`, ); expect(response.status).toEqual(200); });```

tjones
2021-02-23 16:09
you can also do `provider.mockService.baseUrl`: ```test('returns correct body, header and statusCode', async () => { const response = await getStates( provider.mockService.baseUrl ); expect(response.status).toEqual(200); });```

patrick.hendron
2021-02-23 18:38
Hey guys, wondering if someone can expalin this error in a bit more detail https://github.com/pact-foundation/pact-node/blob/b0765b067b354df5e41e9c5f37f3fa69e8d84738/src/publisher.ts#L130 ? - its happening now in my project when I go over a certain amount of interactions for pact contract

jordan.levin
2021-02-23 19:14
has joined #pact-js

patrick.hendron
2021-02-23 19:18
nevermind, looks like my tests where taking longer than the default timeout for pact verfy (30 sounds), added timeout to the options and configured my timeout, working now :slightly_smiling_face:

francesco.latorre
2021-02-24 05:59
has joined #pact-js

aniket.g2185
2021-02-24 09:13
has joined #pact-js

sundaresank360
2021-02-24 12:12
has joined #pact-js

uladzislau_danilchyk
2021-02-24 13:01
Hello there! I'm just trying to understand how to work with `pact-jest` package. Could anyone help me with that? It just needed to have true logs instead of using default behaviour in pact-js. I'm talking about the issue and recommendation in https://github.com/pact-foundation/pact-js/issues/605 In previous version of my pact test I had a separate file with pact config of consumer, provider, mock url, etc. But using this `pact-jest` package I have to use `withPact` method to wrap my consumer tests and put into method object with config. Is there any possibility to load config from separate file for `withPact` as it was done before through `--setupFiles ./config/pact/setup.js`? I don't want to pass and duplicate config properties every time in every consumer test.

jhawthor
2021-02-24 15:18
has joined #pact-js

chris.r.thomas
2021-02-24 16:54
has joined #pact-js

peter.cook
2021-02-24 17:05
has joined #pact-js

jhawthor
2021-02-24 18:28
Greetings! How does one specify the length of a string property in a consumer pact. i.e. If my body has a property "name" how do I specify a max length for the value of name?

jayeshguru81
2021-02-24 18:34
has joined #pact-js

ben.kirberger
2021-02-24 19:16
has joined #pact-js

francis.lobo
2021-02-24 19:42
Hello there! Is there a pact-jas equivalent for `eachKeyLike` in pact-jvm?

jayeshguru81
2021-02-24 19:59
Hello Team, I have just started learning more about pact as we have React repo and Python Microservice which I would like to make contract test for. I have seen jest-pact and pact-foundation in imports in many examples. I would like to understand what is the difference between two?

brendan.donegan
2021-02-24 20:09
jest-pact is a wrapper library specifically for Jest, which you are probably using as your project is React based

brendan.donegan
2021-02-24 20:09
pact-foundation is the more general library that underpins it and can be used in any Javascript based project

jayeshguru81
2021-02-24 20:10
So do you recommend me using jest-pact?

brendan.donegan
2021-02-24 20:10
Yes

jayeshguru81
2021-02-24 20:10
Thanks

jayeshguru81
2021-02-24 20:10
thats helps

jayeshguru81
2021-02-24 20:11
If there are any jest-pact examples you can point me to that would be really great

jayeshguru81
2021-02-24 20:11
I can create our first jest test

brendan.donegan
2021-02-24 20:12
The example on the README is good enough - https://github.com/pact-foundation/jest-pact

jayeshguru81
2021-02-24 20:12
ok great thanks

francis.lobo
2021-02-24 20:42
@jayeshguru81 those examples are good. I got my Jest pact tests running last week based on them.

francis.lobo
2021-02-24 20:43
Another good one is here : https://github.com/YOU54F/jest-pact-typescript/tree/master/src/pact THis is based on typescript

jayeshguru81
2021-02-24 20:49
Thanks do you have a example repo which uses jest-pact as I tried with those examples but seems not working for me yet. It seems I am missing something

jayeshguru81
2021-02-24 20:49
I have added `jest-pact` and `pact-foundation/pact` in my package.json

francis.lobo
2021-02-24 22:05
hey Jayesh, all I did was use the above example and change the request and response to the ones that suit my needs. sorry I dont have the working code on public repo

francis.lobo
2021-02-24 22:05
can you run the examples out of box? they are standalone

tjones
2021-02-24 22:23
I?ve just left a long comment on that issue - the short version of the specific question about common config is that the intended approach is to pull it out into a separate file. I?d like to add first class support for common config soon - see https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-02-24 22:24
@jayeshguru81 What specific problems are you experiencing? If you share your code we can give you a hand solving them

jayeshguru81
2021-02-24 22:26
```import api from 'yourCode';```

jayeshguru81
2021-02-24 22:26
this one specially

tjones
2021-02-24 22:27
That?s about importing your own code

tjones
2021-02-24 22:27
Your api layer

jayeshguru81
2021-02-24 22:31
yeah but was not sure what to import as I have `services.js` file which makes an Api call ```import axios from 'axios'; export const fetchInitialAssets = batchId => { const endpoint = `${UPLOAD_API_SERVICE_URL}/get_batch_by_id/${batchId}`; return axios .get(endpoint, { headers: { authorization: `Bearer ${token}`, }, }) .then(response => response.data); };```

jayeshguru81
2021-02-24 22:31
So should I be importing `import fetchInitialAssets from ../services`

tjones
2021-02-24 22:32
Yes, and you will need a way to inject `UPLOAD_API_SERVICE_URL` into it

jayeshguru81
2021-02-24 22:35
ok thanks let me try this out

tjones
2021-02-24 22:41
To your original question: jest-pact is a convenience wrapper for writing pact tests with jest

tjones
2021-02-24 22:43
There?s no need to use it, but it provides some of the boilerplate and jest-specific setup for you, so it should be a nicer experience for new users

jayeshguru81
2021-02-24 22:44
ok nice thanks Tim..I am newbie in Javascript/React/Jest world..so pardon me for my dumb questions

tjones
2021-02-24 22:45
Not dumb at all. And, asking these questions here is what the channel is for :+1:

matt.fellows
2021-02-24 22:58
Regex / term matcher

matt.fellows
2021-02-24 22:58
But think hard it that's really important for the consumer to restrict

jhawthor
2021-02-24 23:02
I feel as though if the consumer is defining the contract, they should also define the property attributes such as max length, bool, yes/no, etc. After all it's their data that is being processed based on the customer story. I hope that makes sense.

jhawthor
2021-02-24 23:03
This is especially important is data is stored in a SQL DB.



tjones
2021-02-24 23:10
^ I?ve updated the example and slightly modified your code. Apologies for the changes to the export/import style

tjones
2021-02-24 23:11
Hopefully this will help you get going

matt.fellows
2021-02-24 23:30
The second point is fair

matt.fellows
2021-02-24 23:31
see also https://docs.pact.io/consumer/ and specifically the section on ?Only make assertions about things that will affect the consumer if they change?

matt.fellows
2021-02-24 23:31
there?s no absolute right/wrong here, but I just want to ensure you?re aware of the tradeoffs

abubics
2021-02-25 00:09
In this case, I'd push that to the interaction state, like "given: name is too long", and then it's the provider's job to know what its limit is (because it's stored in the DB).

abubics
2021-02-25 00:09
If it's a UI-validated constraint, then it shouldn't even make it to the API client, and it's not part of the contract.

abubics
2021-02-25 00:11
But if the API client wants to say "no, this response from the provider is invalid because a field is too long", then that's a contract thing . . . I guess that might want to be specified by Pact, but I've never come across that kind of situation.

abubics
2021-02-25 00:14
Worst case, you do it just outside the Pact bit, with regular unit-test assertions, in the same test.

jhawthor
2021-02-25 04:08
It just seems to me that if I am the consumer writing the pact for a REST provider, I would want to specify the the property attributes when using JSON in order to comply with the JSONschema. In the JSONschema, you specify the properties as well as the property attributes. Example can be found here: https://www.jsonschema.net/home Otherwise, a JSONschema would be need by the provider as well as a pact stating "I send this object" and "expect this object". So can a pact work with a JSONschema? Or is it just limited to a basic description of an object and what is expected in return leaving the other details to be covered by additional non-pact contract specifications?

jhawthor
2021-02-25 04:14
The default example does not show a maxLength or enum[] property attribute, but can be added by editing the JSONschema.

abubics
2021-02-25 04:30
JSON Schema is great, but not trying to solve the same problems. You can use them together, to get different kinds of feedback. JSON Schema is not consumer- or provider-driven, and can be used for validation on both ends, in both requests and responses.

abubics
2021-02-25 04:31
JSON Schema is similar to Swagger, in that it says what the general shapes of responses can be, but doesn't describe interactions (which include variations of state).

abubics
2021-02-25 04:37
If you want to specify the length of strings, you can use a regex (like `.{16}` or something). I would be wary of doing that, unless it's actually a hard requirement of the consumer. For example, the consumer might break if a field comes back with the wrong date format, or a malformed GUID, or something, so it makes sense to be in the contract. But if it's a display name in the response, and the database has a max length, but the UI is flexible, then that test doesn't need to live in the contract. It should definitely be tested somewhere else, and if implemented in multiple places (e.g. form validation and also API and DB client), you need to work out how to keep them in sync.

abubics
2021-02-25 04:37
If it's a string length in the request that you want to constrain, I would make separate test cases for it. That's a whole separate category.

jhawthor
2021-02-25 04:55
True, but the same would apply to other types as well. So it would seem that passing a JSONschema would prove to be more appropriate, especially for the provider, than passing a simple pact as it would be more representative of an actual contract. Testing the interaction/inoperability would not be very different from what a pact-broker does now.

abubics
2021-02-25 05:00
One of your points is definitely on the money: Pact isn't trying to solve all testing problems, and some tools are better for different kinds of testing. The other side I'm not really understanding. A schema can say, for example, that a field has to be present and a certain length, or that a bunch of fields are optional. A contract (via Pact) will describe which conditions require certain fields to be present. They're both useful, and not equivalent.

m.stephkan
2021-02-25 05:30
has joined #pact-js

francis.lobo
2021-02-25 05:34
bump :arrow_up: Anyone here know if there is an equivalent in pact-js to the pact-jvm matcher `eachKeyLike` ?

francis.lobo
2021-02-25 05:37
We have a use case similar to the one mentioned in https://github.com/pact-foundation/pact-specification/issues/47 we are using eachKeyLike when writing DSL from pact-jvm Now are a bit stuck generating contracts from JS. Any insight on how to use the JS matchers in this case will be really helpful

uglyog
2021-02-25 05:38
There isn't in the core pact-js. I'm checking the V3 beta version to see if it supports it

uglyog
2021-02-25 05:42
No, I didn't add it because there are issues with the implementation in Pact-JVM. See https://github.com/pact-foundation/pact-specification/issues/47 for a replacement

uglyog
2021-02-25 05:43
Can you raise an issue for this? It needs to be tagged with V3.

matt.fellows
2021-02-25 06:16
There is not

matt.fellows
2021-02-25 06:17
Ah sorry, I saw the notification and responded. But it didn't show Ron's response

matt.fellows
2021-02-25 06:17
What Ron said :rolling_on_the_floor_laughing:

matt.fellows
2021-02-25 07:01
So on the JSON schema thing, DM me offline and we talk about a feature we've just added to Pactflow around OAS and pact interop

matt.fellows
2021-02-25 07:01
But also, what everything Andras said

matt.fellows
2021-02-25 07:01
Schema != Contract

matt.fellows
2021-02-25 07:02
In fact, I may find away to make this very prominent in the docs because it's coming up a lot recently


francis.lobo
2021-02-25 08:11
Thanks for the response gents. Will raise an issue

stephen.tjasink
2021-02-25 08:23
has joined #pact-js

matt.fellows
2021-02-25 08:32
:+1:

jayeshguru81
2021-02-25 13:40
Thanks a lot Tim you are a hero..I will do this and try

jayeshguru81
2021-02-25 14:26
I keep on getting this error while running my test - ```Missing `pino-pretty` module: `pino-pretty` must be installed separately```

jayeshguru81
2021-02-25 14:27
I tried to include `pino-pretty` module in my `package.json` 's resolution section too

jayeshguru81
2021-02-25 14:28
We are using prettier for formatting our files

jayeshguru81
2021-02-25 18:05
```Missing `pino-pretty` module: `pino-pretty` must be installed separately 1 | 'use strict'; 2 | > 3 | import {pactWith} from 'jest-pact'; | ^ 4 | import {Matchers} from '@pact-foundation/pact'; 5 | 6 | import {fetchInitialAssets} from '../../services';```

yousafn
2021-02-25 19:05
Put pino-pretty and pino in your devDeps in package json or dev section if you also use pino in your app code Passing in your endpoint url is also the best way as shown above, as it makes it far easier to test :ok_hand: Good luck on your journey lad!

yousafn
2021-02-25 19:09
Ooooh! Maybe a v1 is near

jayeshguru81
2021-02-25 19:45
Nope we don't use `pino` and `pino-pretty` at all, that's why not able to understand why I am getting that error

jayeshguru81
2021-02-25 19:45
is it because `jest-pact` need it ?

beatrizwaclawek
2021-02-25 20:27
has joined #pact-js

zhoutianli1234
2021-02-25 21:09
has joined #pact-js

neild
2021-02-25 21:31
My issue was that I was receiving a dynamic variable through the query string that was used in a middleware. I ended up stubbing the middleware out to return a fixed response no matter what the query string variable was


francis.lobo
2021-02-26 00:05
Is there any alternate recommendation/workaround to do a dynamic key matching in Pact JS right now ?

jayeshguru81
2021-02-26 00:08
i tried to create these again but it seems to give this error again

uglyog
2021-02-26 00:11
I don't think there is. @matt.fellows might be able to confirm. But i will try get this implemented as a priority to help you.

francis.lobo
2021-02-26 00:20
If it can be prioritized, that would be awesome :star-struck:

matt.fellows
2021-02-26 03:11
The v3 branch of Pact JS also has a ?value from provider state? function, that let?s you map this

travis.day
2021-02-26 04:06
has joined #pact-js

sagupta
2021-02-26 09:41
Morning, I came across an article in docs about some recommended patterns on organising your interactions in separate files and some more tips on using pact-js. Cant find that now . If someone knows the link , can you please link here ? Thanks


andrew.cunningham
2021-02-26 11:13
has joined #pact-js

jayeshguru81
2021-02-26 11:46
Has anyone faced below issue with jest-pact?

andrew.cunningham
2021-02-26 11:54
@andrew.cunningham has left the channel

tjones
2021-02-26 15:58
Jest pact doesn?t use either of those modules. If you?re able to upload a reproducible example somewhere, we can take a look. Does this keep happening if you delete package-lock and node_modules?

jayeshguru81
2021-02-26 16:00
Just now one developer suggested me to downgrade my node version to `v11` as I was using `v15` which is much recent version and it solved `missing pino-pretty` issue

jayeshguru81
2021-02-26 16:01
I did that and deleted node_modules and reinstalled `npm install` so it passed that issue now

jayeshguru81
2021-02-26 16:01
now I can concentrate on real issues with my tests

jayeshguru81
2021-02-26 16:03
Just wanted to check if I need to do some configuration for contract tests ?

jayeshguru81
2021-02-26 16:04
like setting up the loalhost pact broker somewhere

jayeshguru81
2021-02-26 18:19
I take my words back, pino-pretty error is still happening even after downgrading node version to `11.0.0`

jayeshguru81
2021-02-26 18:21
Also ripped open yarn.lock file and found `@pact-foundation/pact` has a dependency on `pino-pretty` which is where it is coming from

brendan.donegan
2021-02-26 18:25
indeed it does

jayeshguru81
2021-02-26 18:35
I see `pino-pretty` got installed in the `node_modules`

jayeshguru81
2021-02-26 18:35
but it is missing in `@types` , could that be the reason it is not able to find?

brianmasschaele
2021-02-27 13:27
has joined #pact-js

jayeshguru81
2021-02-27 17:11
Its weird issue which comes after running `yarn` for installing dependencies for some node version, when I tried same thing with `npm install` it worked fine. I dont see any difference while installing deps with both commands but should be something odd

pedroefajardo_pactio
2021-02-27 17:18
has joined #pact-js

tjones
2021-02-28 22:38
I don?t know, sorry. Sounds like a yarn issue, maybe?

jayeshguru81
2021-02-28 22:39
Yes seems to me

tjones
2021-02-28 22:40
To your questions- the pino-pretty types aren?t part of the exported interface of pact-js (unless you?re importing the logger from within the internals), so the `@types` isn?t a dependency

tjones
2021-02-28 22:41
You only need `@types/xxx` if you?re using Typescript and doing development using whatever `xxx` is

jayeshguru81
2021-02-28 22:41
Oh OK thanks for clarifying

tjones
2021-02-28 22:42
> Just wanted to check if I need to do some configuration for contract tests ? It depends what you mean. Usually you wouldn?t run the broker locally at all. If you want to spin one up to see how it all fits together it is possible

jayeshguru81
2021-02-28 22:44
I meant mocking provider locally for doing development

jayeshguru81
2021-02-28 22:44
which I guess we are already doing by mockService.baseUrl

tjones
2021-02-28 22:44
No, you don?t need to mock the provider during development, pact does this for you


jayeshguru81
2021-02-28 22:45
sure will give this a read

tjones
2021-02-28 22:45
The config that you need for writing contract tests is in the example I sent - if you can install that example, you have everything you need

jayeshguru81
2021-02-28 22:46
I got missing requests and unexpected requests errors while running my contract tests

tjones
2021-02-28 22:46
if you want to share your contract with a provider, then you?ll want a broker (it is possible to do this without, but it is much much easier with)

jayeshguru81
2021-02-28 22:46
thats why I thought I am missing some configuration

tjones
2021-02-28 22:46
Ok. This is usually because the expectations are not matching the actual sent

tjones
2021-02-28 22:47
you can check the pact log file (linked in the test fail) to see the details

tjones
2021-02-28 22:47
often it?s headers that you?re expecting that aren?t being sent or vice versa

jayeshguru81
2021-02-28 22:48
yeah on that point I think bearer token is generated and I am not sending correct token

jayeshguru81
2021-02-28 22:48
could that be the reason

tjones
2021-02-28 22:48
so, if your request sent is subtly different (say you expect `X` but you sent `x`), then the error will say that it is missing `X` and it got the unexpected request `x`


jayeshguru81
2021-02-28 22:49
so do I need to send real bearer token in my requests?

tjones
2021-02-28 22:49
In the example I sent you, I had a specific bearer token generated for tests

tjones
2021-02-28 22:50
There are a few different approaches for testing bearer tokens

tjones
2021-02-28 22:50
which one makes sense for you will depend on your use cases and ecosystem

tjones
2021-02-28 22:51
I prefer the ?assume that `"TOKEN"`is a valid token? approach

tjones
2021-02-28 22:51
then in your provider verification, you can stub your auth layer

tjones
2021-02-28 22:51
But depending on how your system works, this may not be appropriate

tjones
2021-02-28 22:53
If you?re still having trouble, post your code and we can take a look

jayeshguru81
2021-02-28 22:54
yeah thats what I was wondering how could I mock the bearer token but will check if we have some examples here. As you said it varies per system, so it might be a challenge here to mock auth token

jayeshguru81
2021-02-28 22:55
Also I do not know why Unexpected requests says `OPTIONS` when I am sending `GET` calls

jayeshguru81
2021-02-28 22:55
```console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /get_batch_by_id/test_batch_id Unexpected requests: OPTIONS /get_batch_by_id/test_batch_id```

tjones
2021-02-28 23:03
Right, so this is because your http library is sending cors preflight checks

tjones
2021-02-28 23:03
add `cors: true` to your pact options

tjones
2021-02-28 23:03
this will tell the mock provider to expect cors preflight requests

jayeshguru81
2021-02-28 23:12
oh ok, cool thanks got it

jayeshguru81
2021-02-28 23:12
I will keep you posted if it works, thanks a lot again for your big help on getting me started here

tjones
2021-02-28 23:21
You?re welcome! Once you?ve got it all working together, it should be much easier the second time

jayeshguru81
2021-02-28 23:26
yes agree :+1::skin-tone-2:

tjones
2021-03-01 00:30
FYI: We?re going to rename `pact-node` to `pact-core` to better reflect the purpose of the package. No action will be required from users (especially if you?re using `@pact-foundation/pact`).

dominic_herrmann
2021-03-01 06:54
has joined #pact-js

dominic_herrmann
2021-03-01 07:03
Hey Folks J, we are building up a new web application using Angular 11. In our code we have got input fields getting submitted to a spring boot rest service. The service call in Angular/Typescript looks like that:     *const url = `${environment.baseURLService}/${this.path}`;* * *     *return this.http.get<OurResponse>(url, {*       *params: search.getParamsArray()*     *})*       *.pipe(catchError(error => this.handleError(error)));* Search.getParamsArray() delivers a Map with our search paramters from the input fields. Beside that we are using Jasmine and PactWeb in order to generatet he Pact File, the contract between our frontend and rest service. Here is an Example snippet out oft he Pact File:        *"description": "Person with name Peter NotFound is found",*       *"providerState": "Person with name Peter NotFound exists",*       *"request": {*         *"method": "GET",*         *"path": "/pc/v1/service",*         *"query": "name=Peter+NotFound"*       *},*       *"response": {*         *"status": 200,*         *"headers": {*           *"Content-Type": "application/json",*           *"Access-Control-Allow-Origin": "*"*         *},*         *"body": {*           *"person": [*             *{*               *"name": "Peter NotFound",*               *"birthdate": "04.07.1978"*             *}*           *]*         *}*       *}*     *}* Our real service and our angular client are working well together. But if we start up MockServer WebRick 1.3.1 with our generated PACT File via  pact-stub-service --cors --port 1234 ./pacts/gui-rest-service.json For our search with name ?Peter NotFound? we get the following error: *No interaction found for GET /pc/v1/service?name=Peter%20NotFound* * * *The Problem is that our WebRick Mock Server can handle only request with + instead of %20. How can we get rid of that Problem?* *We are using , , *

tjones
2021-03-01 07:22
`%20` is space, but your expectation is looking for a plus. I think using plusses for spaces is only valid when the encoding is `application/x-www-form-urlencoded`, which I _think_ might not be valid for a get

uglyog
2021-03-01 07:52
Plus is valid for older browsers, because HTML 2 spec says to encode query parameters using form url encoded scheme. Later specs and RFCs only mention the percent encoding scheme.


dominic_herrmann
2021-03-01 07:57
Because PactWeb and Jasmine generate + for space in generated PACT File. Our question is why does this differ to Angular/Typescript behaviour generating %20. Can we get them synchronous?

tjones
2021-03-02 04:18
What does your test code look like?

ranjanayush03
2021-03-02 10:31
Hi I have a query , as in java we have matchPath option to validate a regex so similarly in javascript what is the option for the same.

dominic_herrmann
2021-03-02 12:02
*describe('Service', () => {* *let provider: PactWeb;* *const expectedPerson: Person = {* *name: 'Peter NotFound',* *birthdate: '04.07.1978'* *}* *beforeAll(function (done) {* *provider = new PactWeb({* *port: 1234,* *host: 'localhost',* *spec: 3* *});* *// required for slower CI environments* *setTimeout(done, 2000);* *// Required if run with `singleRun: false`* *provider.removeInteractions();* *});* *afterAll(function (done) {* *provider.finalize()* *.then(function () {* *done();* *}, function (err) {* *done.fail(err);* *});* *});* *beforeEach(() => {* *TestBed.configureTestingModule({* *imports: [* *HttpClientModule* *],* *providers: [* *Service* *],* *});* *});* *afterEach((done) => {* *provider.verify().then(done, e => done.fail(e));* *TestBed.resetTestingModule();* *});* *describe("Test", () => {* *const expectedResponse: PersonResponse = {* *person: [expectedPerson]* *}* *beforeAll((done) => {* *provider.addInteraction({* *state: `Person with name Peter NotFound exists`,* *uponReceiving: `Person with name Peter NotFound is found`,* *withRequest: {* *method: 'GET',* *path: '/pc/v1/service',* *query: { name: `Peter NotFound` }* *},* *willRespondWith: {* *status: 200,* *body: {* *person: [expectedPerson]* *},* *headers: {* *'Content-Type': 'application/json',* *'Access-Control-Allow-Origin': '*'* *}* *}* *}).then(done, error => done.fail(error));* *});* *it(`Person with name Peter NotFound is delivered`, (done) => {* *const service: Service = TestBed.get(Service);* *service.getPerson(personSearch).subscribe(response => {* *expect(response).toEqual(expectedResponse);* *done();* *}, error => {* *done.fail(error);* *})* *})* *});*

matthew.long
2021-03-02 14:08
has joined #pact-js

tmoncm
2021-03-02 17:17
has joined #pact-js

dcorrales
2021-03-02 19:48
hey folks, apologies if this has already been asked - is there a way to specify that a json attribute can be either a string or null?

brendan.donegan
2021-03-02 20:28
this is a very common question. short answer is ?if it can be a string or *null* and the provider returns null, how do you know that?s not a bug??


dcorrales
2021-03-02 20:34
hey @brendan.donegan thanks for the info. I was leaning towards a second example with our possibly null fields, but wanted to double check just in case :sweat_smile:

dcorrales
2021-03-02 20:34
appreciate the help :slightly_smiling_face:

matt.fellows
2021-03-02 21:19
You just use the regex matcher on the path property itself

matt.fellows
2021-03-02 21:20
There is at least one example in the repo somewhere

phoenixcampos01
2021-03-02 21:25
has joined #pact-js

phoenixcampos01
2021-03-02 21:58
Hey guys, I'm not sure if this is the right place for this question, but this is the language I'm using. I'm trying to just test an async message provider locally by specifying a path to a fake consumer pact json. However, I'm not sure whether this is the intention of that feature given that there seems to be no documentation for the structure of that json. Is the intention to download the json from the broker and then run the verification against that, so really only the broker knows the structure of the json? Or is there an easy way to generate the json?

matt.fellows
2021-03-02 22:26
Do you have a message consumer for it? You should be first writing a consumer test and then using the contract it generates

matt.fellows
2021-03-02 22:26
It's the same as HTTP pact in that regard

matt.fellows
2021-03-02 22:26
Also the pact specification governs the structure of that file


andrewshtamburg
2021-03-02 23:00
has joined #pact-js

andrewshtamburg
2021-03-02 23:04
Hey! I'm just starting with pact and facing some issues. I wrote a simple app and trying to cover it with contract test. At the moment I'm getting this error while trying to run test ```Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves``` The test and function under test is in the thread. I'd really appreciate if you could guide me through what I'm doing wrong here

andrewshtamburg
2021-03-02 23:05
Here is the function that makes a call to the back end

andrewshtamburg
2021-03-02 23:07
Here is the test

andrewshtamburg
2021-03-02 23:12
Here is the function that makes a call to the back end

andrewshtamburg
2021-03-02 23:16
Here is what I'm getting upon running the tests.

matt.fellows
2021-03-02 23:55
Have you tried increasing the timeout?

matt.fellows
2021-03-02 23:56
What does the log file say?

joel.whalen
2021-03-03 00:31
We have been using jest pact successfully in all our pipelines for a few months now, but this dependency issue just popped up in development now: ```18:13:56 Error: Cannot find module 'jest-jasmine2' 18:13:56 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15) 18:13:56 at Function.resolve (internal/modules/cjs/helpers.js:30:19) 18:13:56 at normalize (/pub/jenkins/workspace/zoro.com/development/node_modules/jest-config/build/normalize.js:693:34) 18:13:56 at readConfig (/pub/jenkins/workspace/zoro.com/development/node_modules/jest-config/build/index.js:220:68) 18:13:56 at process._tickCallback (internal/process/next_tick.js:68:7) 18:13:56 at Function.Module.runMain (internal/modules/cjs/loader.js:744:11) 18:13:56 at startup (internal/bootstrap/node.js:285:19) 18:13:56 at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)``` This happens immediately after our jest command to run pact: ```18:13:55 > jest web/static/scripts/ --runInBand --config jest.pact.js``` This error happened in our common development pipeline, otherwise the feature branch would not have been allowed to even merge into it in the first place. Does a dependency update need to happen? Or is it something else?

tjones
2021-03-03 00:32
Hmm. I can?t think of a reason that jest-pact is responsible for this, but that doesn?t mean it isn?t

tjones
2021-03-03 00:32
what version of jest do you have?

joel.whalen
2021-03-03 00:33
25.5.4

tjones
2021-03-03 00:34
I think this might be a config issue - is there something in your jest config that shouldn?t be?

tjones
2021-03-03 00:36
or, is it a corrupt node_modules / package-lock? jest-jasmine2 is a dependency in that version of jest

tjones
2021-03-03 00:37
jest-pact doesn?t have many dependencies, and only uses the public api from jest

joel.whalen
2021-03-03 00:39
Contents of `jest.pact.js`: ```const merge = require('lodash/merge'); const commonJest = require('./jest.common'); module.exports = merge({}, commonJest, { testEnvironment: 'node', testRegex: '/*(.pact.ts)', });``` which is merging with `jest.common.js`, here: ```const babelConfig = require('./babel.jest'); module.exports = { verbose: true, testEnvironment: 'jsdom', resolver: 'jest-directory-named-resolver', moduleFileExtensions: [ 'js', 'vue', 'json', 'ts', 'ts.vue', ], globals: { 'vue-jest': { babelConfig, tsConfig: './tsconfig.json', }, 'ts-jest': { babelConfig, isolatedModules: true, tsConfig: './tsconfig.json', }, }, clearMocks: true, transformIgnorePatterns: [ 'node_modules/(?!(zoro-component-library|vuetify/lib)/)', ], transform: { '^.+\\.js$': './gulp/jestTransformer.js', '.*\\.vue$': 'vue-jest', '.*\\.ts$': 'ts-jest', }, moduleNameMapper: { '^beforeunload-request$': '<rootDir>/node_modules/beforeunload-request/dist/beforeunload-request.min.js', 'cache-helper-RUN_ENV': '<rootDir>/web/static/scripts/base/util/cache-helper-server.ts', 'performance-RUN_ENV': '<rootDir>/web/static/scripts/services/performance/performance-test-stub.ts', '^scripts/(.*)$': '<rootDir>/web/static/scripts/$1', '^~scripts/(.*)$': '<rootDir>/web/static/scripts/$1', '^zoro$': '<rootDir>/web/static/scripts/base/global/zoro.js', '^_gb$': '<rootDir>/web/static/scripts/base/global/_gb.js', '^_gbGlobal$': '<rootDir>/web/static/scripts/base/global/_gbGlobal.js', '^bridgeData$': '<rootDir>/web/static/scripts/base/global/bridgeData.js', '^console$': '<rootDir>/web/static/scripts/base/global/console.js', '^pageData$': '<rootDir>/web/static/scripts/base/global/pageData.js', '^fancybox$': '<rootDir>/node_modules/fancybox/dist/js/jquery.fancybox.js', '^bootstrap/(.*)$': 'bootstrap-sass/assets/javascripts/bootstrap/$1', '^package.json$': '<rootDir>/package.json', '^~zcl/(.*)$': '<rootDir>/node_modules/zoro-component-library/lib/$1', '^vuetify/(.*)$': '<rootDir>/node_modules/vuetify/$1', '^~vue/(.*)$': '<rootDir>/web/static/vue/$1', '^~store/(.*)$': '<rootDir>/web/static/vue/store/$1', '^~sass/(.*)$': '<rootDir>/web/static/styles/sass/$1', '^~tests/(.*)$': '<rootDir>/web/static/scripts/unit-tests/$1', '^~erp/(.*)$': '<rootDir>/web/erp/lib/$1', 'zoro-RUN_ENV': '<rootDir>/web/static/scripts/base/global/zoro-server.js', '^.+\\.(c|le|sc|sa)ss$': 'identity-obj-proxy', }, };``` `babel.jest.js`: ```const babelConfig = require('./babel.common'); module.exports = babelConfig( { targets: { node: 'current' } }, { babelrc: false, plugins: [ ['babel-plugin-transform-imports', { lodash: { // eslint-disable-next-line no-template-curly-in-string transform: 'lodash/${member}', }, }], '@babel/plugin-transform-modules-commonjs', ['dynamic-import-node', { noInterop: true }], ], }, );``` `babel.common.js`: ```const mergeWith = require('lodash/mergeWith'); function mergeCustomizer(objValue, srcValue) { if (Array.isArray(objValue) && Array.isArray(srcValue)) { return objValue.concat(srcValue); } return undefined; } module.exports = ( { targets } = {}, additionalSettings = {}, ) => mergeWith( {}, { presets: [ ['@babel/preset-env', { useBuiltIns: 'entry', modules: false, corejs: 3, ...(targets ? { targets } : {}), }], ], plugins: [ '@babel/plugin-syntax-dynamic-import', '@babel/plugin-transform-runtime', '@babel/plugin-proposal-class-properties', ], }, additionalSettings, mergeCustomizer, );```

matt.fellows
2021-03-03 00:41
This is the ?state of javascript in 2021? medium post right there :point_up:

joel.whalen
2021-03-03 00:41
lmaoooo

tjones
2021-03-03 00:42
I?m wondering if it?s related to one of the module name mappers, but I can?t see anything obvious

tjones
2021-03-03 00:42
I don?t think it?s anything pact-related, though

matt.fellows
2021-03-03 00:44
has something recently changed? I?d be looking to bisect the issue, but with that config :scream:

matt.fellows
2021-03-03 00:44
it looks like jest-jasmine2 is a dependency of jest, so it?s no surprise that?s coming in

matt.fellows
2021-03-03 00:45
so if you ran `npm list jest-jasmine2` does it find the module?

joel.whalen
2021-03-03 00:45
Right, the big tip off for me was that this error happened in our development pipeline. If one of our developers made this change, their feature branch wouldn?t have allowed this to happen.

matt.fellows
2021-03-03 00:45
so that could mean pinning versions migth help?

joel.whalen
2021-03-03 00:46
Jest is pinned though

tjones
2021-03-03 00:46
If you haven?t already, it might be useful to try removing things from the config to see what the cause is. If it does seem to be pact, it would be useful to get a minimal reproducible example

joel.whalen
2021-03-03 00:46
here?s the output of `npm list jest-jasmine2` ```$ npm list jest-jasmine2 @1.0.1 /Users/xjxw304/Documents/BitBucket/environment/microservices/zoro ??? jest@25.5.4 ??? @jest/core@25.5.4 ??? jest-config@25.5.4 ? ??? jest-jasmine2@25.5.4 ??? jest-runner@25.5.4 ??? jest-jasmine2@25.5.4 ```

joel.whalen
2021-03-03 00:46
so it seems to know it?s there, on my local machine at least

matt.fellows
2021-03-03 00:47
yeah cool. If it?s breaking only on CI, can you reproduce by clearing node modules and re-install?

joel.whalen
2021-03-03 00:47
trying now, I?ll get back to you in 40 minutes?.

joel.whalen
2021-03-03 00:47
?yeah this should be a medium post lol

matt.fellows
2021-03-03 00:48
I mean, I won?t read it, but it will probably go viral

joel.whalen
2021-03-03 00:48
?javascript = bad? is always good clickbait

matt.fellows
2021-03-03 00:49
It?s about timing

matt.fellows
2021-03-03 00:50
It actually feels like it?s been a while since one has appeared (but also, i?ve unsubscribed from Medium because their recommendation system just kept giving me more rubbish, and the bottom was essentially reality TV in email form, and I wasn?t willing to fall that far).

matt.fellows
2021-03-03 00:50
so, you know, maybe timing is right (get that paywall up!)

joel.whalen
2021-03-03 00:50
right, reddit or hackernews is a better aggregate for actual good medium posts. Either that, or the top result from google that helps me with whatever error I?m debugging

matt.fellows
2021-03-03 00:55
indeed

joel.whalen
2021-03-03 00:56
npm install might be stuck, I?ll come back later with results it?s already 8pm here

andrewshtamburg
2021-03-03 08:29
Here is what log file says

andrewshtamburg
2021-03-03 08:29
And yes, I tried to increase a timeout with no luck unfortunately :disappointed:

matt.fellows
2021-03-03 08:34
Wrong log sorry, pact should produce a log

andrewshtamburg
2021-03-03 08:38
Sorry for dumb questions, but where do I find this file?

andrewshtamburg
2021-03-03 08:41
`mockserver-integration.log` is empty :disappointed:

andrewshtamburg
2021-03-03 08:44
Change the log level to `DEBUG`, may be this will help.

andrewshtamburg
2021-03-03 08:44
After last line it just hangs and nothing happens until I abort manually

matt.fellows
2021-03-03 08:46
Hmm timeout still seems likely. But please share the pact log file. It's in the `logs` dir according to your setup

andrewshtamburg
2021-03-03 13:05
It was an timeout thing after all. Increased it more it started to work

andrewshtamburg
2021-03-03 13:05
Thanks a lot for your help

joel.whalen
2021-03-03 15:14
after a clean install, the tests run fine on my machine. Also there have been 3 subsequent runs of development where it passes just fine. What a strange, one-off issue.

hugh.paul.mcgowan
2021-03-03 17:52
has joined #pact-js

normanrs
2021-03-04 11:18
has joined #pact-js

sagupta
2021-03-04 12:43
hello team, I am getting this error when running pact tests with jest on CI . Looks like the pact startup is not completed . Has anyone faced a similar issue ```[2021-03-04 12:40:57.917 +0000] ERROR (307 on runner-2bymd9cd-project-94-concurrent-0): pact-node@10.11.8: Pact Binary Error: /gitlab/builds/2BymD9cd/0/<>/dev/graphql/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.37/pact/lib/ruby/bin/ruby: line 6: /gitlab/builds/2BymD9cd/0/<>/dev/graphql/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.37/pact/lib/ruby/bin.real/ruby: No such file or directory```

matt.fellows
2021-03-04 12:55
Looks like the alpine issue

matt.fellows
2021-03-04 12:55
There's a page on the docs for that

jayeshguru81
2021-03-04 12:57
Hey Tim wanted to thank you again as my contract test was completed for the JS repo

sagupta
2021-03-04 13:43
that was a good suggestion because we are indeed creating a container from a alpine node image

sagupta
2021-03-04 13:44
I checked locally by adding the dependencies mentioned here https://docs.pact.io/docker/#reference-image in my Dockerfile

sagupta
2021-03-04 13:45
but now i get a different error ```[2021-03-04 13:41:03.142 +0000] DEBUG (79 on c760da961371): pact-node@10.11.8: Starting pact binary 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service', with arguments [service --consumer graphql --pact_dir /opt/project/pacts --host 127.0.0.1 --log /opt/project/var/pact/logs/pact.log --pact-file-write-mode overwrite --port 8087 --provider email-action-api --pact_specification_version 2] [2021-03-04 13:41:03.150 +0000] DEBUG (79 on c760da961371): pact-node@10.11.8: Created 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service' process with PID: undefined [2021-03-04 13:41:03.156 +0000] ERROR (79 on c760da961371): pact-node@10.11.8: errno: "ENOENT" code: "ENOENT" syscall: "spawn standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" path: "standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" spawnargs: [ "service", "--consumer", "graphql", "--pact_dir", "/opt/project/pacts", "--host", "127.0.0.1", "--log", "/opt/project/var/pact/logs/pact.log", "--pact-file-write-mode", "overwrite", "--port", "8087", "--provider", "email-action-api", "--pact_specification_version", "2" ] [2021-03-04 13:41:03.165 +0000] WARN (79 on c760da961371): pact-node@10.11.8: Pact exited with code -2. [2021-03-04 13:41:03.165 +0000] INFO (79 on c760da961371): pact-node@10.11.8: Removing Pact process with PID: undefined```

sagupta
2021-03-04 13:47
Its not able to create pact mock service and assign a PID

sagupta
2021-03-04 14:17
I have used very simple images and all are getting the same error as above ? A alpine image with necessary dependency ? A full node:8 image

sagupta
2021-03-04 15:52
Hey team , do you know if there is a way to expose child process errors or logs when pact mock service startup process runs. Currently i am getting a error on pact mock service startup running on docker container but doesnt mention what went wrong in terminal ```[2021-03-04 15:49:43.634 +0000] INFO (77 on ebc7eb1bbf0e): pact-node@10.11.8: Creating Pact Server with options: {"consumer":"graphql","cors":false,"dir":"/opt/project/pacts","host":"127.0.0.1","log":"/opt/project/var/pact/logs/pact.log","pactFileWriteMode":"overwrite","port":8087,"provider":"email-action-api","spec":2,"ssl":false} [2021-03-04 15:49:43.695 +0000] DEBUG (77 on ebc7eb1bbf0e): pact-node@10.11.8: Starting pact binary 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service', with arguments [service --consumer graphql --pact_dir /opt/project/pacts --host 127.0.0.1 --log /opt/project/var/pact/logs/pact.log --pact-file-write-mode overwrite --port 8087 --provider email-action-api --pact_specification_version 2] [2021-03-04 15:49:43.703 +0000] DEBUG (77 on ebc7eb1bbf0e): pact-node@10.11.8: Created 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service' process with PID: undefined [2021-03-04 15:49:43.709 +0000] ERROR (77 on ebc7eb1bbf0e): pact-node@10.11.8: errno: "ENOENT" code: "ENOENT" syscall: "spawn standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" path: "standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" spawnargs: [ "service", "--consumer", "graphql", "--pact_dir", "/opt/project/pacts", "--host", "127.0.0.1", "--log", "/opt/project/var/pact/logs/pact.log", "--pact-file-write-mode", "overwrite", "--port", "8087", "--provider", "email-action-api", "--pact_specification_version", "2" ] [2021-03-04 15:49:43.718 +0000] WARN (77 on ebc7eb1bbf0e): pact-node@10.11.8: Pact exited with code -2. [2021-03-04 15:49:43.719 +0000] INFO (77 on ebc7eb1bbf0e): pact-node@10.11.8: Removing Pact process with PID: undefined```

jayson.bailey
2021-03-04 19:18
has joined #pact-js

jayeshguru81
2021-03-04 21:48
Hi Team, We have JS repo which makes call to our internal API, which does not even have baseUrl defined (meaning it calls API through proxy `http://our-intranet-proxy-url/a/cm/associate_products`). In this case services layer just does this and the requested is routed through our intranet url in browser. Does anyone know how we can write pact test for such scenarios? ```export const submitAssociationData = requestData => { const endpoint = `/a/cm/associate_products`; return http://axios.post( endpoint, {requestData} ); };```

matt.fellows
2021-03-04 22:57
are you running on alpine?


matt.fellows
2021-03-04 22:59
there is a note on the Pact JS site/docs also

matt.fellows
2021-03-04 22:59
I think that?s probably the issue

matt.fellows
2021-03-04 22:59
if you can get onto the docker container and try to execute the same command you might find out more also

audun.halland
2021-03-04 23:18
Hi, in pact-js _verification_ (I?m using V3 beta, but seems to also apply to stable version(?)), is there a way to _filter states_ during verification debugging? Looking for something like the `--filter-state` argument to `pact_verifier_cli`.

matt.fellows
2021-03-05 00:08
In v2 you can (if I understand your question)


matt.fellows
2021-03-05 00:10
if it?s _just_ routing the request, I?d find a way to ignore the intermediate layer and re-write the paths later on in a repeatable way


audun.halland
2021-03-05 00:19
Ah, that was why I didn?t find it. I was page-searching for `filter` :slightly_smiling_face: So env var, I think I like that! It doesn?t work in V3 though :stuck_out_tongue:

matt.fellows
2021-03-05 00:26
Probably worth exposing it both as a flag and an env var I reckon

audun.halland
2021-03-05 00:29
I like not having to fear of accidentally committing such a filter

matt.fellows
2021-03-05 00:29
yep

matt.fellows
2021-03-05 00:30
makes sense

tjones
2021-03-05 01:59
Do you see any errors during install? It might not be downloading the binaries correctly

tjones
2021-03-05 02:24
That?s great to hear! You?re welcome :slightly_smiling_face:

matt.fellows
2021-03-05 11:47
Are you mounting the directory from a Mac or windows host? If so, it may not have the Linux binaries installed (because they were installed on the host with the OS specific binary)

matt.fellows
2021-03-05 11:47
Could please share the exact docker command?

matt.fellows
2021-03-05 11:50
Also you could just try and run that command yourself to see if it works, it might give you more specific feedback

matt.fellows
2021-03-05 11:50
Frustrating error though

sagupta
2021-03-05 11:53
I debugged this yesterday with one of the devs and we are also suspecting that it might be due to the linux binaries not installed properly

sagupta
2021-03-05 11:53
Still trying out few options locally , will keep posted as i get some fix

jayeshguru81
2021-03-05 13:58
Thanks @matt.fellows you are right We are just routing the request to the internal kubernetes ingress url `http://kube-my-provider-endpoint.domain.com/api/v1/associate_products` as our API are not public so thats why the request are routed through a proxy. This is a huge pain point because all our APIs are private, so solution to this will unblock us from writing contract tests for everything.Below is my test code for the same CC: @tjones who helped me in creating pact test for our external APIs(which has defined baseUrl) ```'use strict'; import {pactWith} from 'jest-pact'; import {Matchers} from '@pact-foundation/pact'; import {submitAssociationData} from '../../services'; pactWith( { consumer: 'my-frontend-association-repo', provider: 'my-association-api', cors: true, }, provider => { describe('Submit Association Data', () => { const requestBody = { associations: [ { requestor_id: 'test_requestor', requestor_id_type: 'DSID', asset_id: 'test_asset_id', asset_id_type: 'IRE_ID', product_id_type: 'SKU', products: [ {product_id: 'test_product_id_1', is_active: true, is_primary: false}, {product_id: 'test_product_id_2', is_active: true, is_primary: false}, ], }, ], }; const expectedBody = { code: 200, body: { Success: true, }, }; beforeEach(() => { const interaction = { state: 'Asset Association exists', uponReceiving: 'a request for submitting asset association for assetid test_asset_id', withRequest: { method: 'POST', path: '/api/v1/associate_products', }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: expectedBody, }, }; return provider.addInteraction(interaction); }); // add expectations it('returns a successful body', () => { return submitAssociationData( requestBody, provider.mockService.baseUrl ).then(content => { expect(content).toEqual(Matchers.extractPayload(expectedBody)); }); }); }); } );```

tjones
2021-03-05 14:55
Looks like in the internal case you have an empty base URL, because of kube magic? That?s fine, just inject an empty one for production, and modify it to non-empty during pact tests

jayeshguru81
2021-03-05 15:01
ah ok...let me try this

jayeshguru81
2021-03-05 21:19
Thanks again Tim, this worked for me :slightly_smiling_face:

matt.fellows
2021-03-05 22:04
How are you running the container and what commands are you running in it? Please share

matt.fellows
2021-03-05 22:04
I know pact js works in docker, because we do it

matt.fellows
2021-03-05 23:49
that?s what i?d do too

matt.fellows
2021-03-05 23:49
Probably worth us documenting that use case somewhere, it?s pretty common!

matt.fellows
2021-03-05 23:50
Added a reminder to follow up these docs next week

dominic_herrmann
2021-03-08 09:17
Hey, how can we use bigint for IDs while generating PACT File with Jasmine and PactWeb? We are getting error "Do not know how to serialize a BigInt" during "ng test"

matt.fellows
2021-03-08 09:34
you can?t do that, only things that can be serialised in JSON can go into a Pact file. How is it represented over the wire? I?m going to assume a string


dominic_herrmann
2021-03-08 10:20
Thx, not good, in our Java REST Backend it is a long value. If we user a string in typescript, the value in generated pact file is in braces (like all strings), which would not be correct

matt.fellows
2021-03-08 10:21
so this isn?t a Pact issue

matt.fellows
2021-03-08 10:21
the reality is, your Angular App is using BigInt but needs to send it over the wire to Java, but JSON knows no such thing about BigInt.

matt.fellows
2021-03-08 10:22
Given the JSON options are limited to just a few primitives, you have two choices (I think): 1. Serialise it as a number 2. Serialise it as a string

matt.fellows
2021-03-08 10:22
Your Java service should be able to handle how to read either of those into a long value, that?s just mapping stuff

matt.fellows
2021-03-08 10:23
Personally, I?d serialise as a string, because if you need accuracy (and if you?re using BigInt my assumption is that you do) then downcasting to a JSON number may result in a loss of fidelity

matt.fellows
2021-03-08 10:24
> ? If we user a string in typescript, the value in generated pact file is in braces (like all strings), which would not be correct I think you mean quotes? i.e. `"`

dominic_herrmann
2021-03-08 10:40
Yes I meant quotes

alan.hanafy
2021-03-08 20:40
probably more of a karma question, but is there a way to set the PactWeb({port:number}) based on the configured value in the karma.conf file? What i mean is: ```//karma.conf.js ... // Pact Providers pact: [ { port: 1234, consumer: "KarmaJasmineConsumer", provider: "KarmaJasmineProvider", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }, { port: 4321, consumer: "KarmaJasmineConsumer", provider: "SecondKarmaJasmineProvider", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }, ], ... // // client-spec.js ... //// //somehow i load karmaPactProviders from the karmaconfig file /// describe("Client", function() { var provider var secondPactProviderPort = karmaPactProviders[1].port beforeAll(function(done) { provider = new Pact.PactWeb({ port: secondPactProviderPort }) ...```

matt.fellows
2021-03-08 22:00
I think you can

matt.fellows
2021-03-08 22:12
I recall looking into it a few years ago when we wrote that adapter

matt.fellows
2021-03-08 22:12
I _think_ one thing that could be done, is to append to the `client` once the plugin starts, which is then made available to the `__karma__` global.

matt.fellows
2021-03-08 22:13
I?m not sure if that is accessible now, a quick google seems to not turn up much, but I don?t use Karma very often so I?m not very familiar with it

mjsmcp
2021-03-08 23:46
has joined #pact-js

javier.garcia_cotado
2021-03-09 21:52
has joined #pact-js

matt.fellows
2021-03-10 03:39
Anyone here using Karma or `pact-web`? If so, we?d appreciate your feedback on https://github.com/pact-foundation/pact-js/issues/626

matt.fellows
2021-03-10 03:40
Tim and I are currently more on the side of ?remove? than keep. It?s going to be a hard call - because the key trade of is ?a lot of effort to update (to latest features) and maintain? vs ?reduced DX for Karma use cases?

tjones
2021-03-10 06:38
Thanks Matt! We?re very interested to hear from users of Karma + pact. I think it?s now much easier to do testing of the API layer without running testing in a browser, but I don?t want to remove support for it if it?s something that people are doing because it?s required by the tools they?re using.

akos.csurai
2021-03-10 13:39
has joined #pact-js

akos.csurai
2021-03-10 14:11
@akos.csurai has left the channel

testme2020testme
2021-03-10 14:12
has joined #pact-js

mjsmcp
2021-03-10 17:05
Our build system runs builds in a jail with no network access, so the postinstall script for `@pact-foundation/pact-node` is failing when it tries to pull the standalone binary from GitHub. Is there a known workaround for this?

tommy.mirchandani
2021-03-10 17:13
has joined #pact-js

mjsmcp
2021-03-10 17:14
Ah, think I found it.

matt.fellows
2021-03-10 20:22
I know there was an issue fixed around this recently, did you get it to work?

mjsmcp
2021-03-10 20:22
I did. Downloading the tar.gz into my build closure did the trick.

varinderjitkaur13
2021-03-11 01:46
has joined #pact-js

francis.lobo
2021-03-11 03:48
Hey folks, Quick question on https://github.com/pact-foundation/pact-js/issues/618 Can someone tell me a rough estimate on when this could be available (I am not looking at exact dates, but more like approx 'X' weeks/months ) This will help us priorities our Pact-js related activities. Cheers!

uglyog
2021-03-11 03:51
The underlying libraries support it, it just needs the JS DSL to be updated.

uglyog
2021-03-11 03:51
Probably be done in about a month

francis.lobo
2021-03-11 04:55
sweet thanks for the update @uglyog. that helps :+1:

krcl.dev
2021-03-11 05:11
has joined #pact-js

mahdi.ali
2021-03-11 09:46
has joined #pact-js

krishnaraoveera1294
2021-03-11 17:53
has joined #pact-js

raghavendra.kalakonda
2021-03-11 23:08
has joined #pact-js

tjones
2021-03-12 05:09
set the channel topic: Questions and updates about Pact in JS/TS/node. See also #pact-js-development for contribution or development questions. All questions welcome!

andries.spies
2021-03-12 07:25
has joined #pact-js

kamil.klima
2021-03-12 11:38
has joined #pact-js

lswanborough
2021-03-15 00:50
has joined #pact-js

danhitchcock
2021-03-15 18:21
Hi there, two of my requests to the mock server in my client tests are grumbling about missing the authorisation header, the respond/req with doesn't specify it needs one. Am I missing something basic here? All my other requests don't hit this issue.

don.tobias
2021-03-15 19:35
has joined #pact-js

matt.fellows
2021-03-15 22:43
Can you please share your tests?

matt.fellows
2021-03-15 22:43
I?m wondering if there is some state / sequence issue where previously requests aren?t being cleared.

danhitchcock
2021-03-16 09:35
Will do, sorry for the absence of code.

danhitchcock
2021-03-16 09:48
OK so investigating the code that calls the api, it appears there is a wrapped fetch that takes the response body url (the one I am expecting) and GETs a Csv from said url.

danhitchcock
2021-03-16 09:54
A

matt.fellows
2021-03-16 09:56
aha

matt.fellows
2021-03-16 09:57
so you might need to register 2 expectations for that, or separate it out such that the API calls can be tested separately

danhitchcock
2021-03-16 09:58
In my head that was the process now I know. Do I just add another interaction then I guess?

matt.fellows
2021-03-16 09:59
yep

matt.fellows
2021-03-16 10:00
or as per above, you could separate the two API calls into separate functions (and have a third that combines them still preserving that behaviour) and test them separately

matt.fellows
2021-03-16 10:00
whatever makes the most sense

danhitchcock
2021-03-16 10:04
:thumbsup: Cheers for the help Matt. I imagine this won't be a the first of its kind, splitting the api means precious Dev time so I'll go with your first suggestion and mention it might be an idea to split them. :mechanic: Thank you again for your support :raised_hands:

matt.fellows
2021-03-16 10:06
You mention dev time - is that somebody else or would that also be you doing that? What?s your role in this process?

danhitchcock
2021-03-16 11:33
Someone else, another FE Dev. Guess my role is FE dev/test in this process

sagar.kathuria
2021-03-17 04:25
has joined #pact-js

shao.sum
2021-03-17 08:35
has joined #pact-js

riddhichopra
2021-03-18 01:28
has joined #pact-js

anu.de
2021-03-18 02:28
has joined #pact-js

sreyaslj
2021-03-18 04:25
has joined #pact-js

ashish.joshi
2021-03-18 08:57
Hey Folks :wave: Can anyone help me why am I getting this error in my provider test: `Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer]`      `Pact::ProviderVerifier::SetUpProviderStateError:`       `Error setting up provider state 'xyz-state' for consumer 'my-consumer-abc' at http://localhost:50346/_pactSetup. response status=500 response body={}`

ashish.joshi
2021-03-18 08:58
this is happening for some selected interactions/states for others it is working fine.

matt.fellows
2021-03-18 10:07
if you could please enable `trace` logging and share that? (redacting any sensitive data of course) that would help.

matt.fellows
2021-03-18 10:07
it looks like the provider state `xyz-state` handler you?ve setup is broken

ashish.joshi
2021-03-18 18:44
Hey Matt, trace logs are also similar

ashish.joshi
2021-03-18 18:48
So i have 3 different consumer services which my single provider test is verifying, ? 1st service has 5 interactions, all five are verified, ? 2nd service has 2 interaction, first is passing second failing due to above error ? 3rd service has 3 interactions, second is passing and first and third are failing due to above error

waquino
2021-03-18 20:07
Hi, is anybody using pact-node in arm64?

waquino
2021-03-18 20:07
`255.1 error @pact-foundation/pact-node@10.11.4: The CPU architecture "arm64" is incompatible with this module.`

waquino
2021-03-18 20:07
i?m getting this error when i try to deploy

matt.fellows
2021-03-18 21:35
Are you on the new M1 macs or something else?

matt.fellows
2021-03-18 21:38
Are you sure they?re trace? I?m pretty sure we should be getting more output

matt.fellows
2021-03-18 21:38
what does your code look like?

ashish.joshi
2021-03-18 21:39
I added this line to my Verifier options: `logLevel: 'DEBUG'`

ashish.joshi
2021-03-18 21:50
``` const OPTIONS_BASE = { provider: 'my-provider', providerBaseUrl: url, pactBrokerUrl: 'https://my-pactbroker-link', publishVerificationResult: false, logLevel: 'DEBUG', providerVersion: `${version}`, requestFilter: (req, res, next) => { req.url = req.url.replace( 'unwanted_url_in_some_endpoints', 'required_url_for_some_endpoints' ); req.headers['required_auth'] = 'my-token'; next(); } }; it('should validate following test', () => { return new Verifier({ ...OPTIONS_BASE, ...getStateHandlers(hockInstance, db) }).verifyProvider(); });```

ashish.joshi
2021-03-18 21:52
and `getStateHandlers` is the function which contains all states for respective services and those states points to respective state-handling functions.

waquino
2021-03-18 21:54
something else, this would be an extract of my github actions flow ```name: Build Docker runs-on: ubuntu-20.04 - name: Build and push id: docker_build uses: docker/build-push-action@v2 with: context: . file: ${{ env.DOCKERFILE_PATH }} platforms: linux/amd64,linux/arm64```

matt.fellows
2021-03-18 21:57
I need to see those, because the failure is likely happening there

matt.fellows
2021-03-18 21:57
It's that, or the request filter

matt.fellows
2021-03-18 21:58
Try removing each handler one by one until that specific failure goes away. Then you'll know why

ashish.joshi
2021-03-18 22:00
tried by removing the request filter but it still failed for one of the interaction where req-filter was not required.

ashish.joshi
2021-03-18 22:02
And tried by removing all the interactions except one failing interaction in pact file, it still was not able to setup and didn't ping the provider service

ashish.joshi
2021-03-18 22:06
However, in my state-handler function i am inserting data to database, mocking some internal calls. If i remove those required code from the state-handler function in that case it ping the provider service and throw error saying that data is required in db or that particular internal call is not mocked. but if i add that required mocks/db insertions it fails in pact setup and is not pinging the provider service.

matt.fellows
2021-03-18 22:08
The error doesn't surprise me because we don't test against arm

matt.fellows
2021-03-18 22:08
Do you need to run pact tests in both architectures?

matt.fellows
2021-03-18 22:09
@tjones any ideas? I saw something around M1 the other day.

tjones
2021-03-18 22:11
We don?t have binaries for arm64 yet, so it won?t work. On Mac you can get around it with Rosetta, but I don?t know how it would work with Linux

ashish.joshi
2021-03-18 22:13
```function getStateHandlers(hockInstance, db) { return { stateHandlers: { //consumer-service-1 'consumer-service-1-get-abc': getAbc(hockInstance, db), 'consumer-service-1-post-xyz': updateXyz(hockInstance, db), //consumer-service-2 'consumer-service-2-post-demo': updateDemo(hockInstance, db), 'consumer-service-2-post-cba': UpdateCba(hockInstance, db), 'consumer-service-2-get-jkl': getJkl(hockInstance, db), //consumer-service-3 'consumer-service-3-rollback': rollback(hockInstance, db), 'consumer-service-3-post-qpo': updateQpo(hockInstance, db) } }; }```

matt.fellows
2021-03-18 22:13
Looking at the above, it doesn't seem like a necessary thing for Wellington

matt.fellows
2021-03-18 22:14
Hmm

ashish.joshi
2021-03-18 22:16
this is my `getStateHandlers` function :point_up:, consumer-service-1: all interactions are fine consumer-service-2: only this is working `consumer-service-2-post-cba` other 2 are failing consumer-service-3: this is failing `consumer-service-3-post-qpo`

ashish.joshi
2021-03-18 22:21
the respective handling functions are kept in different file as per different consumer services. Example of such function for one of the failing states: ```function updateDemo(hockInstance, db) { return async() => { const collection = db.collection(REQUIRED_COLLECTION); await collection.insert(MY_DEMORECORD, function(err, result) { if (!err) { console.log('Inserted MY_DEMORECORD'); } }); //mocked call hockInstance .post(`required mock url for internal call`, { body_property1: 'abc', body_property2: 'bcd' }) .any() .reply(200, stub_response, RESPONSE_HEADERS); }; }```

arvind1017
2021-03-18 22:48
has joined #pact-js

matt.fellows
2021-03-18 23:25
might be worth a try/catch and seeing if there is an exception there

matt.fellows
2021-03-18 23:25
I?m fairly confident the `trace` logging should show more than what we?re seeing here

matt.fellows
2021-03-18 23:26
if you comment out the states, does the exception you?re seeing go away? (tthe tests are likely to fail, obviously, but it would at least focus us on the root cause)

ashish.joshi
2021-03-18 23:55
finally try-catch worked and got the issue, there were some variable need to updated, But is weird that we can not see any details on that in any logs, pact verifier should throw some error, at-least stateting something wrong in this state handler function

matt.fellows
2021-03-19 00:06
yeah, I agree

matt.fellows
2021-03-19 00:08
Could you please raise an issue for this on Github? I?ll get that added, should be easy to do and provide better visibility

matt.fellows
2021-03-19 00:09
it?s a poor experience!

ashish.joshi
2021-03-19 00:09
Sure, Thank you Matt :thumbsup:

sushilvc84
2021-03-19 00:30
has joined #pact-js

tjones
2021-03-19 03:34
I?m not sure that Travelling Ruby supports arm64 on Linux. It might not be straightforward to get the binaries

matt.fellows
2021-03-19 04:15
yep, I was thinking the same. Probably another reason to focus on the Rust port

tejakoshti7
2021-03-19 06:26
has joined #pact-js

yannick.adler
2021-03-19 12:44
has joined #pact-js

waquino
2021-03-19 13:11
do you guys recommend me staying away of arm64 for the time being? is there any plan or road map to supported in the future?

matt.fellows
2021-03-19 13:14
No plans, but our plans are largely based on community need - I.e. by you folks. Raise a request on Pact JS and we'll prioritise it there

matt.fellows
2021-03-19 13:14
And yes, I'd steer clear for now

matt.fellows
2021-03-19 13:15
It looks like you run multiple OS tests, so maybe just run the pact ones on Linux for now

waquino
2021-03-19 13:50
Thanks :slightly_smiling_face: i?ll update our tests

kjayachandra2000
2021-03-19 14:09
has joined #pact-js

smith260194
2021-03-19 17:41
@smith260194 has left the channel

aelse
2021-03-19 23:54
has joined #pact-js

eric2323223
2021-03-20 01:35
has joined #pact-js

jordan.r.stewart
2021-03-20 16:07
has joined #pact-js

tmorrison
2021-03-21 21:45
has joined #pact-js

a.chandrasekaran
2021-03-22 00:50
has joined #pact-js

maksym.motornyi
2021-03-22 11:50
has joined #pact-js

gareth.somerville
2021-03-22 12:10
has joined #pact-js

joseph.method
2021-03-22 19:55
has joined #pact-js

dennyg666
2021-03-22 20:54
has joined #pact-js

me1295
2021-03-23 00:15
has joined #pact-js

francis.lobo
2021-03-23 01:27
@uglyog just checking if there is any new news on this? is there any change or delay This will help me keep our plans updated

uglyog
2021-03-23 02:25
Pact-js needs to be updated to support it. That needs to be coordinated with @tjones and @matt.fellows

anchit.99
2021-03-23 09:04
has joined #pact-js

ashish.joshi
2021-03-23 16:25
Issue Added :thumbsup:


wola.adedeji
2021-03-23 16:25
has joined #pact-js

kenny.shobowale
2021-03-23 16:38
has joined #pact-js

victoria.kruczek
2021-03-24 09:42
hello, I hope you have a great day so far :slightly_smiling_face: I?m writing with an issue/question: So I have an endpoint which has to have a parameter, and I don?t know where to add it. I?ve tried on the provider side via `customProviderHeaders` and directly in consumer file by adding params to `uponReceiving` block: ``` params: { filter: {"countryCode":"DE"}, },``` Both of those didn?t do the job and I?m not sure what now. I also tried to add the param directly in the `path` but I get an error back from Pact: ``` Missing requests: GET /api/submissions?filter=[%7B%22countryCode%22:%22PL%22%7D]& Unexpected requests: GET /api/submissions?filter=[%7B%22countryCode%22:%22PL%22%7D]&``` I?ve tried to dig in the docs and https://github.com/pact-foundation/pact-js#provider-state-callbacks, but to be honest, I?m lost after reading it. Guess I?m not so tech advanced :sweat_smile: Can anyone help with this? :pray:

anbu.pandian
2021-03-24 11:54
has joined #pact-js

victoria.kruczek
2021-03-24 13:12
I managed to fix it. The problem was the encoding :facepalm: The solution is that you have to add a `query` to your `uponReceiving` block: ```query: { "filter": "[{\"countryCode\":\"DE\"}]"},```

rachel.barton
2021-03-24 19:12
has joined #pact-js

james522
2021-03-24 22:06
has joined #pact-js

francis.lobo
2021-03-25 00:25
Thanks @uglyog

francis.lobo
2021-03-25 00:26
Hey @tjones / @matt.fellows do you folks have any news on this? I am only looking at rough timelines so that we can align our planning accordingly

matt.fellows
2021-03-25 00:27
I?ll look at it on my next OSS day, which is either tomorrow or early next week

matt.fellows
2021-03-25 00:27
But it might take a week or so of review/feedback etc.

francis.lobo
2021-03-25 00:30
cool. That helps. Thanks @matt.fellows :+1:

anne.schuth320
2021-03-25 07:49
has joined #pact-js

victoria.kruczek
2021-03-25 10:01
hello, hope you have a great day so far :slightly_smiling_face: I have a question regarding negative tests: What I don?t understand is why the console is returning back an error if the expected response is indeed 409? ``` Submissions - delete a submission ? returns data of the created submission (27 ms) ? Pact between App consumer and Submissions API ? with 30000 ms timeout for Pact ? Submissions - delete a submission ? returns data of the created submission Request failed with status code 409``` I feel it?s misleading, because we do expect the 409, so the tests should pass then, right? :thinking_face: Or should I do some extra steps to handle those negative tests in Pact? Here?s the test block for reference: ``` describe('Submissions - delete a submission ', () => { const submissionsExpectedReceivedData = { "code": "Conflict", "message": "Not_deletable", }; const submissionResponse = { status: 409, headers: { 'Content-Type': 'application/json', }, body: submissionsExpectedReceivedData, }; const submissionsDeleteRequest = { uponReceiving: 'a request to delete a submission', withRequest: { method: 'DELETE', path: `/${submissionId}`, headers: { Accept: 'application/json, text/plain, */*', }, }, }; beforeEach(async () => { const interaction = { state: 'i want to delete a submission', ...submissionsDeleteRequest, willRespondWith: submissionResponse, }; return provider.addInteraction(interaction); }); it('returns data of the created submission', async () => { const result = await Submission.delete( provider.mockService.baseUrl, ); expect(result).toEqual(submissionsExpectedReceivedData); }); });```

brendan.donegan
2021-03-25 10:27
Are you sure the error isn?t coming from your client code?

brendan.donegan
2021-03-25 10:27
To me it looks like Pact is doing it?s job and responding with 409 and the client has an issue with that

brendan.donegan
2021-03-25 10:28
You would have to set your test up to make the error ?allowed? as with any other jest test

brendan.donegan
2021-03-25 10:30
``` expect(() => { const result = await Submission.delete( provider.mockService.baseUrl, ); }.toThrow('Request failed with status code 409');```

brendan.donegan
2021-03-25 10:30
Also you could just try/catch

matt.fellows
2021-03-25 10:47
Ah, sorry Brendan! Victoria just joined our Q&A (see #general) and that?s exactly what?s happening. :taco: for a quick response though!

victoria.kruczek
2021-03-25 10:48
Haha, I?m still star struck :smile:

victoria.kruczek
2021-03-25 10:48
thank you! :slightly_smiling_face:

brendan.donegan
2021-03-25 10:59
I?d really love to join but have another meeting :confused: Next one!

victoria.kruczek
2021-03-25 11:00
Done, I went with the try/catch: ``` it('returns data of the created submission', async () => { await SubmissionSDK.delete( provider.mockService.baseurl, ).catch((e) => { expect(e.response.data).toEqual(submissionsExpectedReceivedData); }) });``` thank you again for the help! :slightly_smiling_face:

matt.fellows
2021-03-25 11:07
all good, it was just a 30 min. We?ll do better to advertise next time. It?s no event, it?s just us being there to answer questions and chat!

james.shirtcliffe
2021-03-25 12:04
has joined #pact-js

brendan.donegan
2021-03-25 12:05
I had questions :smile:

brendan.donegan
2021-03-25 12:07
Just FYI that?s the ?Promisey? way of catching, with async/await you would do ```try { await SubmissionSDK.delete( provider.mockService.baseurl, ) } catch (e) { expect(e.response.data).toEqual(submissionsExpectedReceivedData); }```

serhii.makarenko
2021-03-25 12:55
has joined #pact-js

mashabudryte
2021-03-25 14:35
has joined #pact-js

mashabudryte
2021-03-25 14:41
~resolved~

matthew.simon.barnes_
2021-03-25 16:08
has joined #pact-js

sagupta
2021-03-25 16:22
hello team, We have successfully established consumer tests for one provider. Now we are looking to add tests for more providers in the consumer repo. Can someone please share how are they running the tests. ? Do you run mock server in each of the tests per provider or we can run mock server once for all provider tests? ? We are also looking to group all contract tests using a utility called `jest-runner-groups` so that we can run all provider tests in CI with one command. Has anyone tried it ?

joseph.method
2021-03-25 17:33
I have a matcher that looks like this: ```term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } )```

joseph.method
2021-03-25 17:33
I need the escape characters because it?s a string right?

joseph.method
2021-03-25 17:34
But then I?m getting this error when I run the test ```WARN: Ignoring unsupported matching rules {"match"=>"regex", "regex"=>"\\d{4}-\\d{2}-\\d{2}"}```

matt.fellows
2021-03-25 22:59
I?m confused about your question

matt.fellows
2021-03-25 22:59
You don?t use the mock service on the provider side - you need to start your actual provider

matt.fellows
2021-03-25 22:59
I?m not familiar with that tool and the benefits it provides over simply running the pact tests

matt.fellows
2021-03-25 22:59
what are you trying to achieve by ?grouping? them?

abubics
2021-03-25 23:48
kinda sounds like a version mismatch, but I'm pretty sure regex has been around (in Pact) forever :thinking_face:

danhitchcock
2021-03-26 07:04
Missing a trailing slash at a guess, haven't had coffee yet so happy to be wrong :coffee:

abubics
2021-03-26 07:06
These are ruby regexes stored as JSON strings, so unlikely to be related to `/` characters at the start & end :slightly_smiling_face:

danhitchcock
2021-03-26 07:08
Have you got a full copy of the request you can safely share?

jose.manzano
2021-03-26 14:27
has joined #pact-js

sagupta
2021-03-26 15:56
Sorry if My question confused you ,i am talking about consumer tests which setup mock server .I now want to add tests for more providers like Consumer a ?> Provider A Consumer a ?> Provider B Consumer a ?> Provider C So far I have initialized pact mock server with host ,port,pact directory and logs directory in the test for Provider A .If I want to add Provider B tests do I need to initialize pact mock server again or we can define only once and reuse the same pact mock server . Also I would like to have pact files per provider generated so for Provider A ,Provider B and provider C separate . By grouping ,I mean I can tag all these tests with let?s say ?contractTest? so I can just run all by running one command like jest ?group=contractTest

joseph.method
2021-03-26 16:13
The documentation gives as an example `F|M` which would correspond to `/F|M/`

chris.faulkner
2021-03-26 16:13
has joined #pact-js

joseph.method
2021-03-26 16:15
The issue is that I have to escape the `\` so that `\d`isn?t just escaping `d` , but then the `//d` is showing up in the Ruby regexp which is unexpected?

joseph.method
2021-03-26 16:18
e.g. without that double slash I get the error (in Node): `Error: Example '2021-03-01' does not match provided regular expression 'd{4}-d{2}-d{2}'`

joseph.method
2021-03-26 16:21
Okay, I need to stop thinking about the slashes because those are a red herring: `WARN: Ignoring unsupported matching rules {"match"=>"regex", "regex"=>".*"}`

bryanw
2021-03-26 18:46
has joined #pact-js

abubics
2021-03-28 22:55
yeah, "unsupported matching rules" is what I'm more concerned with

joseph.method
2021-03-28 23:22
One important detail is that this is a match inside the query of the request

joseph.method
2021-03-28 23:27
But there is an example in the documentation that matches in the query

abubics
2021-03-29 01:03
Oh, all the matchers in the readme are for body fields . . . I remember matcher support in query params wasn't the same, and maybe came later. I can't even see query params in the readme at all :thinking_face:

abubics
2021-03-29 01:08
https://github.com/pact-foundation/pact-js/blob/62bb7fcf8262bea47617756fa00d72f1561bb766/examples/karma/jasmine/client-spec.js#L64, there's a regex matcher that looks like yours. Can you show us more of your code? (like the whole interaction, or somehting)

joseph.method
2021-03-29 01:31
`provider.addInteraction({ state: 'Invoices are present', uponReceiving: 'request for /api/invoices', withRequest: { method: 'GET', path: '/api/invoices', query: {` `filter: { issued_date: term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) } },` `}, willRespondWith: { status: 200, body: expectedBody, }, });`

joseph.method
2021-03-29 01:32
This is Mocha

abubics
2021-03-29 02:51
that's cool, the Pact DSL doesn't change :slightly_smiling_face:

abubics
2021-03-29 02:51
I have a feeling that query params don't support nesting like that

abubics
2021-03-29 02:51
what does the complete URL look like when that query param is present?

kerem.durak
2021-03-29 08:34
has joined #pact-js

sagupta
2021-03-29 11:10
@matt.fellows Just need your inputs :)

dave.clissold
2021-03-29 12:40
has joined #pact-js

joseph.method
2021-03-29 16:26
ohhhhhh I?ve been thinking in Rails terms

joseph.method
2021-03-29 16:26
`/api/invoices/123?filter[issued_date]=2021-03-01`

joseph.method
2021-03-29 16:27
so I bet I just need to put that in duh

joseph.method
2021-03-29 16:35
Hmm this doesn?t work either: ```query: { 'filter[issued_date]': term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) },```

sidhant.bhayana.15
2021-03-29 18:34
has joined #pact-js

abubics
2021-03-30 00:10
yeah, I think that's a non-standard (but semi-common) convention

abubics
2021-03-30 00:12
someone more familiar with the implementation details and/or spec will need to respond, I'm not sure about it

abubics
2021-03-30 00:14
This is the best docs I can find about it, and it doesn't know anything about that syntax: https://docs.pact.io/getting_started/matching/#query-params

abubics
2021-03-30 00:17
Just bumping this back to the main channel, because I don't know the answer. Is there support for this kind of nested syntax in any pact-consumer version?

matt.fellows
2021-03-30 00:40
hmmm good question

matt.fellows
2021-03-30 00:41
So i?m not surprised that the nesting example above doesn?t work, but I would have expected this to work: ```query: { 'filter[issued_date]': term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) },```

matt.fellows
2021-03-30 00:42
So, all of this aside, it?s first worth asking the question - do you really need a matcher on the query string? Presumably you can control the consumer code, so you don?t need to ?regex? it.

matt.fellows
2021-03-30 00:42
The request matchers aren?t used when the provider is verified, so it?s only for the consumer test

joseph.method
2021-03-30 01:33
Hmm that's true. The underlying fixture data is created in the providerstate with the current month but it could be hardcoded to the value instead

matt.fellows
2021-03-30 01:36
> WARN: Ignoring unsupported matching rules {?match?=>?regex?, ?regex?=>?.*?} @bethskurrie might know more. I know these warnings aren?t always correct

matt.fellows
2021-03-30 01:37
If you could share the Pact, I could eyeball it to double check it?s being serialised correctly

uglyog
2021-03-30 01:45
are you referring to the query parameter array syntax?

abubics
2021-03-30 01:50
yep, and there's more discussion in the thread

bethskurrie
2021-03-30 02:28
```{ filter: { issued_date: term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) } },```

bethskurrie
2021-03-30 02:28
I don't think that format is supported in JS

bethskurrie
2021-03-30 02:28
I think you'll need to use the square bracket format.

bethskurrie
2021-03-30 02:29
But that is a super flakey area because of the way params are serialized and deserialized differently by every language/server.

bethskurrie
2021-03-30 02:31
Can you make a reproduction of the issue by forking pact-js and modifying one of the examples please @joseph.method

matt.fellows
2021-03-30 02:32
> I don?t think that format is supported in JS Yeah I?ve never tried it. The serialiser should recurse the object and add the matchers, but not sure the HTTP mock service knows what to do. At least, it?s untested

matt.fellows
2021-03-30 12:08
> So far I have initialized pact mock server with host ,port,pact directory and logs directory in the test for Provider A .If I want to add Provider B tests do I need to initialize pact mock server again or we can define only once and reuse the same pact mock server . It?s recommended to have a separate mock for each. This way, those tests could be run in parallel (if you wanted to) but it?s less complicated. You can re-use the same one, but it will just result in confusing test code

matt.fellows
2021-03-30 12:09
With the grouping tool, that?s up to you and how you arrange them. If it?s helpful, go for it

sagupta
2021-03-30 16:23
```It's recommended to have a separate mock for each. This way, those tests could be run in parallel (if you wanted to) but it's less complicated. You can re-use the same one, but it will just result in confusing test code``` So that means , I need to run them on different ports also right

crhawkins85
2021-03-30 21:02
has joined #pact-js

matt.fellows
2021-03-30 21:14
correct

matt.fellows
2021-03-30 21:14
I tend not to specify ports, and let the framework pick a free one

matt.fellows
2021-03-30 21:15
that way, you don?t need to worry about port conflicts on CI etc.

pranav.gore
2021-03-31 01:58
has joined #pact-js

sagupta
2021-03-31 07:14
nice yea that makes sense, i will try it out then like this

matt.fellows
2021-03-31 08:58
:+1:

harsha6988
2021-03-31 12:19
has joined #pact-js

harsha6988
2021-03-31 12:23
I am using provider verification as : ```return new Verifier(opts).verifyProvider().then(output => { console.log("Pact Verification Complete!") console.log(output) })``` in my source code.. While executing this in my local - mac os - it is verifying the pact properly. However when same code i am trying to execute in bitbucket pipeline.. it is giving an error as: `1) Pact Verification` `Should validate the consumer:` `Error: /opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.40/pact/lib/ruby/bin/ruby: line 6: /opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.40/pact/lib/ruby/bin.real/ruby: No such file or directory` `at ChildProcess.<anonymous> (node_modules/@pact-foundation/pact-node/src/verifier.ts:272:55)` `at maybeClose (internal/child_process.js:1021:16)` `at Socket.<anonymous> (internal/child_process.js:443:11)` `at Pipe.<anonymous> (net.js:674:12)`

matt.fellows
2021-03-31 13:22
Running on Alpine linux?

matt.fellows
2021-03-31 13:23
Check out the docs

harsha6988
2021-03-31 13:54
Yes

leixu
2021-03-31 14:42
has joined #pact-js

matthew.brown
2021-03-31 15:15
has joined #pact-js

oleksandr.tryshchenko
2021-03-31 19:54
has joined #pact-js

matt.fellows
2021-03-31 23:23
See the docs on alpine linux on JS repo/docs.pact.io

phelantomas
2021-04-01 13:13
has joined #pact-js

ktogias
2021-04-01 20:04
has joined #pact-js

balaji.sivakumar
2021-04-02 05:41
has joined #pact-js

jayson.bailey
2021-04-02 20:31
Probably a dumb question, but is there any good documentation/examples on setup? I have `const provider = new Pact({..})` in several `.test.pact.ts` files and whichever is run last overrides the previous pact output file, so I only end up with those interactions in it.

ktogias
2021-04-03 11:51
Hi. I solved this problem by putting all my tests in the same suite and initializing the provider in beforeAll. Then on each test i add the corresponding ingeraction to the provider. This way I get a Pact file containing all the interactions. I had to put all tests in the same spec.js file. I don't know if a suite can be split in multiple files.


matt.fellows
2021-04-03 21:52
You can split across tests

jayson.bailey
2021-04-05 14:40
Thanks for the replies!

uryadov212
2021-04-05 20:52
has joined #pact-js

soumya.aithal966
2021-04-05 22:45
has joined #pact-js

francis.lobo
2021-04-05 22:56
Hello @matt.fellows did you get a chance to look into this one?

tjones
2021-04-06 00:08
Also, which testing framework are you using? `jest-pact` solves some of this for Jest, and we have some better config for everyone in the roadmap


sheyan.rizfee
2021-04-06 00:55
has joined #pact-js

matt.fellows
2021-04-06 04:23
Hi Francis! Apologies, I didn?t get the OSS day I was hoping for last week, and it?s been a long weekend here in Australia. I?ll be looking at this tomorrow.

francis.lobo
2021-04-06 04:58
Thanks @matt.fellows

greg719
2021-04-06 09:23
has joined #pact-js

piotr
2021-04-06 09:24
has joined #pact-js

greg719
2021-04-06 09:25
hey just wanted to confirm. If I omit port in PactWeb configuration then it will take a random port based on provider name correct?

matt.fellows
2021-04-06 09:47
Not in pact web

matt.fellows
2021-04-06 09:48
It can't communicate to the mock server without knowing the port (because it's designed to run in a browser, so can only communicate via http)

matt.fellows
2021-04-06 09:48
Do you really need to us pact web? We're thinking of dropping support for it if I'm honest, but keen for feedback

dmitry.korolev
2021-04-06 11:47
has joined #pact-js

greg719
2021-04-06 12:56
what should i use then?

matt.fellows
2021-04-06 13:28
Just straight pact (not the pact web variant) with mocha/jest/...

matt.fellows
2021-04-06 13:28
Is there a reason you went for Pact Web?

greg719
2021-04-06 13:34
i think we were lead by examples / documentation (maybe old one)

greg719
2021-04-06 13:35
right now we migrating to NX that is using Jest

greg719
2021-04-06 13:36
ok confirmed in new NX we do not use PactWeb

greg719
2021-04-06 13:36
so to confirm, this one does not need the port right?

sravyavadrevu988
2021-04-06 20:40
has joined #pact-js

johnnycareer
2021-04-06 21:34
has joined #pact-js

matt.fellows
2021-04-07 00:58
that?s correct

matt.fellows
2021-04-07 00:58
it should return the server details in the promise returned from `setup()`

matt.fellows
2021-04-07 00:58
If you could find any docs/examples you used as a basis for your tests, that would be helpful.

matt.fellows
2021-04-07 00:58
I suspect there are many people using PactWeb incorrectly (despite it not being advertised widely at all)

matt.fellows
2021-04-07 01:47
Looking at this now Francis

matt.fellows
2021-04-07 01:47
:crossed_fingers: it?s not a massive thing. Might take a few iterations to get it right, but let?s see how we go!


matt.fellows
2021-04-07 06:08
the e2e test has an example using it

francis.lobo
2021-04-07 06:15
Woohoo awesome :party_parrot: Will give it a squiz and get back to you early next week Thanks heaps @matt.fellows

yousafn
2021-04-07 08:36
Anyone been messing about with deno? I?ve recently heard about it over the last few weeks and it keeps cropping up so I am going to have a play at the weekend building some bits and bobs and want to have a look at if pact can work in deno land

matt.fellows
2021-04-07 11:38
Apart from looking at it and thinking ?shit, more interop to be concerned about? no :stuck_out_tongue:

matt.fellows
2021-04-07 11:39
It seemed to make a big noise 6 or so months ago (I dunno with Covid, my sense of time is broken). But haven?t heard much of it recently myself

matt.fellows
2021-04-07 11:40
Definitely keen to see how the interop goes. The biggest risk would be the interface to the Ruby process. I?m not sure if it has the same install stages, which is how we download and extract the CLI. It should have a way to invoke an external process, so should be ok

matt.fellows
2021-04-07 11:40
the new v3 branch with Rust will be interesting. I?d suspect it currently wouldn?t work, because it?s tied to the current node ABI, which I?m assuming is not going to be compatible with Deno (or at least, there be dragons()

matt.fellows
2021-04-07 11:41
This should change, as we?re looking to use more of an FFI style binding, so it should just delegate to standard OS syscalls. But that might be node specific as well :man-shrugging:

matt.fellows
2021-04-07 11:41
TL;DR - keen to hear how you go :slightly_smiling_face:

danil.nurgaliev
2021-04-07 12:26
has joined #pact-js

yousafn
2021-04-07 12:27
They just announced some major funding and have launched as a company, so it might be making some more noise. It uses rust so yeah working with v3 would probably be the plan. I?m just interesting to dip my toe in the water and see whats what. Started looking at the testing framework but the docs were down, but noted some nice fellows have built jest like wrappers so it feels nice and familiar

yousafn
2021-04-07 12:27
Thanks for the feedback Matt, will deffo ping along some links to examples and can build on them from there

matt.fellows
2021-04-07 12:30
Awesome!

matt.fellows
2021-04-07 12:30
Love that you can get stuck into it!

matt.fellows
2021-04-07 12:30
I recall the Rust thing, I think Ron?s ears pricked up when we heard it

matt.fellows
2021-04-07 12:30
Makes a lot of sense for a core engine, because it?s so stable

yousafn
2021-04-07 12:35
I know nothing of Rust, but my tech lead peer raved about it and created a game called Rusticles, so I am very curious to peer under the sheets!

yousafn
2021-04-07 18:37
Got a deno example of the pact-workshop-js provider https://github.com/YOU54F/deno-examples having a look at the react consumer now, and then can add some unit tests and try out pact :)

yousafn
2021-04-08 00:28
This reminds me a lot of the early days of flutter Very experimental apis :joy: Knocked together a very very basic react app that can call the provider api?s, not styled up or tested bar manually. Got the provider covered with a unit test or two. That was a fun little tinker, enjoyed it so far!

tjones
2021-04-08 03:26
I read the original Deno pitch thingy and liked the ideas but thought "this will never catch on". Full disclosure, that's what I thought about node too.

tjones
2021-04-08 03:27
On the one hand I hope it catches on, because it has some really nice ideas that I like much more than the way node works. On the other hand, I share the same reservations about interop as Matt.

tjones
2021-04-08 03:33
I'd love to hear what you think after working with it for a bit, especially if you're trying out pact.

gtsifrikas
2021-04-08 08:53
has joined #pact-js

kanapuramamarnath
2021-04-08 09:18
has joined #pact-js

arnaud.dutrillaux
2021-04-09 10:59
has joined #pact-js

gsinghania
2021-04-09 15:40
has joined #pact-js

souravmohanty35
2021-04-09 16:34
has joined #pact-js

itzdavey
2021-04-09 17:23
has joined #pact-js

tmorrison
2021-04-11 18:45
:wave: Hi all! Pretty new to the Pact community. I saw @matt.fellows present during TestJS Summit and have been working on a POC implementation for my company based on @yousafn awesome repo.

yousafn
2021-04-11 18:52
Welcome dude, glad that repo has been useful! Where do you work?

tmorrison
2021-04-11 18:55
I work at Ally Bank. I'm a frontend tech lead, but also heavily involved in our overall test automation. Our org uses quite a few tools for testing APIs, including Watchman, but I'm working on a pitch to make Pact our new go-to.

yousafn
2021-04-11 20:31
Amazing! Looking forward to hearing about your journey. I am loving working with developers who are so passionate about testing, my place is chock full of them.

tmorrison
2021-04-11 20:35
*QUESTION:* Is https://github.com/pact-foundation/jest-pactnecessary if you have other ways of instantiating `PactOptions` and ensuring the boilerplate is setup properly? *CONTEXT:* I'm a big fan of the https://nx.dev/ monorepo dev tools. I'm thinking about building a community plugin that extends `@nrwl/jest` to setup Pact within a monorepo

yousafn
2021-04-11 20:40
It?s not no, it makes it easier but you can do that yourself with pact js and some helper files. Your context seems really sound, it would be nice to have it as a plugin for easy consumption in nx.

tmorrison
2021-04-11 20:47
Awesome! I started using `jest-pact` based on your example but I think it need to use vanilla `pact-js` to really maximize the executors Nrwl team created. Also it seems like the setup / teardown on each script will be a little more explicit this way.

matt.fellows
2021-04-12 01:37
Welcome Tyler, and so glad the talk was helpful

matt.fellows
2021-04-12 01:38
> Our org uses quite a few tools for testing APIs, including Watchman, but I?m working on a pitch to make Pact our new go-to. So cool! Let us know how we can help.

matt.fellows
2021-04-12 01:39
This Nx thing keeps coming up - I best get across it :stuck_out_tongue:

matt.fellows
2021-04-12 01:39
I should note, we are worknig on a v3 of Pact JS right now (see an early draft of the roadmap here: https://github.com/pact-foundation/pact-js/projects/3)

matt.fellows
2021-04-12 01:40
If you?re looking to extend Pact, we should talk about how we provide the needed hooks in the latest version, as the API will change a little bit

matt.fellows
2021-04-12 01:40
It?s currently in an early https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/, but is used by a number of customers globally (it supports XML, and a bunch of the new v3 matchers)

matt.fellows
2021-04-12 01:41
we?re reworking the way we integrate into the new Rust core engine, which will modify the external facing interface

abubics
2021-04-12 02:02
btw, the super-short answer is: no, jest-pact is not necessary (it's just a DSL wrapper for pact-js) :party_parrot:

tjones
2021-04-12 05:49
What's this Nrwl thing?

tjones
2021-04-12 05:53
> Also it seems like the setup / teardown on each script will be a little more explicit this way. Yes. The main feature of jest-pact is to ensure that the setup / teardown and other jest-specific options are done correctly each time. If you prefer to be explicit about this, then jest-pact is not for you.

tjones
2021-04-12 05:53
(also you will need to be careful to set the things that jest requires, eg `pactWriteFileMode: 'update'`)

brendan.j.donegan
2021-04-12 06:25
Afaik Nrwl are the company that develop Nx


tjones
2021-04-12 06:26
I haven't really found anything substantial for "nrwl pact" in google

tjones
2021-04-12 06:33
(also thanks! However, I still can't find any link between them and pact)

audun.halland
2021-04-12 08:50
@audun.halland has left the channel

greg719
2021-04-12 09:43
I will mention it in my videos going forward :wink:

matt.fellows
2021-04-12 09:54
Ah, you're _that_ Greg - hi :rolling_on_the_floor_laughing:

greg719
2021-04-12 09:56
howdy

tmorrison
2021-04-12 13:34
@tjones TL;DR - No link exists at the moment, but I'm working to change that. Longer version? Nx provides a framework agnostic set of tooling that greatly improves monorepo development. They provide a set of https://nx.dev/latest/react/core-concepts/plugins for the major frameworks ? React, Angular, etc. But they also make it easy for the community to build plugins. In this case, I would like to build a community plugin that extends their core plugin `@nrwl/jest` so that Nx users could easily scaffold Pact tests for either a consumer or a provider

tjones
2021-04-12 22:39
Awesome!

tjones
2021-04-12 22:39
If it's incompatible with jest-pact, let's figure out why and then work to change that

tjones
2021-04-12 22:39
(on whichever side makes sense)

tjones
2021-04-12 22:41
Also, have a look at the config pitch here: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-04-12 22:41
I was tempted to put a lot of config niceties into jest-pact, but chose not to because if we do it in the main package then everyone can benefit

tjones
2021-04-12 22:42
Let me know if I can help in any way

laura.edington
2021-04-13 17:45
has joined #pact-js

liam.mcdermott
2021-04-13 22:38
has joined #pact-js

francis.lobo
2021-04-14 01:31
Hello folks! I need some help using the V3 regex matchers I tried using the following patter in my consumer tests, ``` const apiPathExample = '/api/client/0A050891038CFAFC/copy'; const apiPathMatcher = '/api/client/[A-Z0-9]+/copy'; const interaction: InteractionObject = { .... withRequest: { path: MatchersV3.regex(apiPathMatcher, apiPath), } }``` And ended up with error : `Failed: "{\"message\":\"Error ocurred in mock service: NoMethodError - undefined method `+' for #<Hash:0x3dc6c80>` followed by a ruby stacktrace. I am assuming I am not writing the regex pattern in the right format as expected by the underlying ruby matcher. Also tried escaping the backslashes but that didnt help either `\/api\/client\/[A-Z0-9]+\/copy` I am not very familiar with ruby regex format. Any help in understanding this will be really great. I was using the same patter with v2 matcher.term() but looks like term is not supported in v3. hence trying to use regex

abubics
2021-04-14 01:49
probably don't need to escape the [forward] slashes (`/`) but if it's genuinely falling over on the `+`, it might need to be escaped?

abubics
2021-04-14 01:50
https://rubular.com/ is a good place to play with Ruby regex, if that helps

francis.lobo
2021-04-14 01:51
thanks will try that

matt.fellows
2021-04-14 01:58
The v3 stuff doesn?t use the Ruby engine anymore - they should just be a regular POSIX regex (I think)

matt.fellows
2021-04-14 01:59
buuuut? that does look like a Ruby error

matt.fellows
2021-04-14 01:59
are you using the V3 matchers with the v2 code base? Could you please share the wider code context here?

francis.lobo
2021-04-14 03:28
ah yes! I think that could be the issue.. I had built the test from V2 examples, while trying to move to V3, I have only replaced the Matchers and completely missed out changing the mock server setup.

matt.fellows
2021-04-14 03:29
cc @tjones. :point_up: we need to constrain this sort of thing in our v3 launch

tjones
2021-04-14 03:32
I have a vague plan for this!

matt.fellows
2021-04-14 03:32
I feel types themselves will solve many of the problems (i.e. a v3 scoped matcher shouldn?t fit into a v2 shaped hole)

matt.fellows
2021-04-14 03:33
but the API itself could adress

tjones
2021-04-14 03:33
Aren't we pact-js? What types?

tjones
2021-04-14 03:34
(I don't think we can rely on typescript types to solve our problems completely)

tjones
2021-04-14 03:34
although the types are better in V3

tjones
2021-04-14 03:34
https://github.com/pact-foundation/pact-js/issues/611 ^ I think if we implemented this, we could extend it to know the appropriate matchers for the appropriate interactions

tjones
2021-04-14 03:35
(that's my vague plan)

johnnycareer
2021-04-14 07:34
@johnnycareer has left the channel

kjayachandra2000
2021-04-14 10:39
Hi :wave: All, I have a consumer to be verified by a provider consumer : `cities:{VAL:{name:"India",displayName:"India",countryCode:"IN"}},countries:{IN:{name:"India"}}` provider: `{cities:{DXB:{name:"Dubai",displayName:"DUBAI",countryCode:"AE"}},countries:{AE:{name:"Dubai"}}}` how to add the regular expression for the consumer and the items can be more than 1 item

matt.fellows
2021-04-14 11:10
You'll need to use the new beta v3 branch, which has an `eachKeyLike` matcher, because the keys change

matt.fellows
2021-04-14 11:11
It's like the `eachLike` but for keys that can change instead of the values

wedlaaa
2021-04-14 13:33
has joined #pact-js

kjayachandra2000
2021-04-14 15:24
Hi Matt, thanks, but still i am getting assertion error

lewis.thorley
2021-04-14 21:57
Out of interest - is it possible to conduct a pact test with FormData()? In jest FormData is not defined as it is not part of the jsdom environment. Mocking the global FormData has only ended badly for me as axios did not like the mocked object.

lewis.thorley
2021-04-14 22:07
Figured this out - will write up tomorrow if anyone is interested

wderksen
2021-04-14 22:26
has joined #pact-js

abubics
2021-04-15 01:49
I'm more interested in your use case . . . FormData and jsdom sound like presentation-layer concepts, I wouldn't expect them to be relevant to Pact testing :thinking_face:

mail_4brad
2021-04-15 02:34
has joined #pact-js

lewis.thorley
2021-04-15 06:32
It?s because formData is required to send multi part form data in JS as far as I understand.

abubics
2021-04-15 07:12
I guess, if you have a hard constraint on mutipart/form-data, then that's reasonable :slightly_smiling_face: that use case is common for large uploads, but not much else, and we tend to contract test those less, and limit them to not include other kinds of data in the upload (such as text fields)

abubics
2021-04-15 07:13
That's more what I meant in my original Q, what's the use-case that's pushing you to use FormData in the first place? (or multipart/form-data at the API side)

tjones
2021-04-15 07:49
Does your header return the trailing `;`? I'm not sure that's valid.

tjones
2021-04-15 07:49
Also, this is the channel for pact-js, but you're getting a Java error. Should you be in #pact-jvm?

francislainy.campos
2021-04-15 07:55
Hi, I was actually on pact jvm first but was asked to move the message here. :slightly_smiling_face:

francislainy.campos
2021-04-15 07:55
I?ll check the ; piece. Thanks.

tjones
2021-04-15 07:57
Regardless of how you got here, the contract should state the exact header that your service returns. I think that `application/json;` isn't valid, because `;` is the separator that indicates there's a parameter, but there's no parameter.

tjones
2021-04-15 07:58
This is the section of the spec that defines the content-type field: https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7

francislainy.campos
2021-04-15 07:58
Yes, you?re spot on. I removed that and the tests worked fine. Thanks very much.

tjones
2021-04-15 07:58
You're welcome!

lewis.thorley
2021-04-15 08:14
I am uploading a single file to an API

lewis.thorley
2021-04-15 08:15
My next fun challenge is that axios is making my request body dynamic: ``` "body": '----------------------------892025258273260351389190\r\nContent-Disposition: form-data; name="image"\r\n\r\n{"type":"image/jpeg","file":"blobby"}\r\n----------------------------892025258273260351389190--\r\n' ```

lewis.thorley
2021-04-15 08:16
and that's how the body needs to look otherwise the provider will fail

lewis.thorley
2021-04-15 08:16
starting to think pact may not be best for this scenario :thinking_face:

abubics
2021-04-15 08:58
Looks like https://github.com/pact-foundation/pact-jvm/issues/123 (to JVM at least) 4 years ago

lewis.thorley
2021-04-15 08:59
that's really helpful thank you

abubics
2021-04-15 08:59
It's kind of on the edge (for me) of what should be contract tested, because the content is basically irrelevant, and verifying its format is testing the HTTP library that encodes it.

lewis.thorley
2021-04-15 09:00
yeah I suppose the only thing that is making it valid for me is that our controller is validating the file

lewis.thorley
2021-04-15 09:00
so we need to verify the body

abubics
2021-04-15 09:01
The fact that a valid one will return one response, and an invalid one will return another is what is relevant, but you can't quite separate the (de)serialisation from the other parts of the interface boundary

abubics
2021-04-15 09:03
You don't actually need to verify the body, right? It just need to not crash the conversion to/from an octet stream. You can theoretically avoid verifying the body with states like "valid file" and "invalid file".

lewis.thorley
2021-04-15 09:07
yeah that's it - as long as it hits the controller and we can read the content type from the multi-part request it's fine

abubics
2021-04-15 09:09
Sometimes it's not worth picking that apart, so you just let the framework do more than it needs to :sweat_smile: but good to narrow down which bits are actually relevant :party_parrot:

rodrigo.costa20
2021-04-15 12:08
hey guys! I'm using pact-js for a test on consumer-side and the test works well... however, when I try to run the tests on the CI Tool (bamboo), I keep getting this error "Postinstalled Failed Unexpectedly: Error downloading binary from https://github.com/pact-foundation/pact-ruby-standalone/releases/download ..." and I think this error is probably because the computer where the bamboo runs, is not able to access any external url, so I think when its try to access github, the error is presented. do you guys know what I can do to workaround it? using proxy on CI its not an option in this case


goncalosamuel
2021-04-15 15:08
has joined #pact-js

matthew.hall
2021-04-15 17:36
has joined #pact-js

raony
2021-04-15 19:21
has joined #pact-js

gupta.ratnesh9
2021-04-16 04:48
has joined #pact-js

greg595au
2021-04-16 10:00
has joined #pact-js

manel_ben_yahia
2021-04-16 13:59
has joined #pact-js

kmckeever
2021-04-16 19:26
Hey Rodrigo, we were experiencing this at my organization, and there are a couple ways to handle this. 1. You can include the binary with your repository and specify the pact download location to where your binary is located OR... 2. The preferred approach, and the one we went with: Get your corporate IT to whitelist GitHub URLs, as well as any redirects made by the GitHub URL you posted for the pact binary. If you curl that URL, it should expose what those redirects are, so you can whitelist those.

kmckeever
2021-04-16 19:31
Hey there :wave: Say my provider validation needs me to query for a unique key that changes often and use it to update a property value in the payload for the provider before executing the verification. How would I go about doing this? Is this where provider states come into play? I'm a little hazy on how that would work here.

matt.fellows
2021-04-17 01:11
Provider states are ideally suited to setting up data to match a particular request

matt.fellows
2021-04-17 01:12
If you need to be able to replace a path id e.g. `/users/1234` with `/users/5678` at provider verification time, there is a v3 feature for this: https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/provider-state-injected/consumer

matt.fellows
2021-04-17 01:13
you?ll need to use the v3 project for that: https://github.com/pact-foundation/pact-js#pact-js-v3


maxence
2021-04-17 11:07
has joined #pact-js

kranti.deep
2021-04-17 14:17
has joined #pact-js

aaronw153
2021-04-17 21:42
has joined #pact-js

github
2021-04-19 00:57
GitHub app is successfully upgraded in your workspace :tada: To receive notifications in your private channels, you need to invite the GitHub app `/invite @GitHub`

kranti.deep
2021-04-19 06:59
@kranti.deep has left the channel

dwmahieddine
2021-04-19 12:44
has joined #pact-js

kmckeever
2021-04-19 13:45
I mean to include the instructions for 1! Apologies for that: https://www.npmjs.com/package/@pact-foundation/pact-node/v/10.5.0#installation

garrettmichael
2021-04-19 18:34
has joined #pact-js

daniel.kalleward
2021-04-20 08:16
has joined #pact-js

mattias.persson
2021-04-20 12:45
has joined #pact-js

martin.eklund
2021-04-20 12:47
has joined #pact-js

parveenbanu
2021-04-20 14:43
Hi Friends

parveenbanu
2021-04-20 14:43
I am working on Pact recently.

parveenbanu
2021-04-20 14:44
I have downloaded the base of my API Services and developed Pact scripts with help of consumer and provider.

parveenbanu
2021-04-20 14:44
locally it is running successfully.

parveenbanu
2021-04-20 14:44
While i try to push the code to GITLAB it is returning error

parveenbanu
2021-04-20 14:45
npm run test:consumer https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L247 > business-services-core@0.1.23-rc.3 test:consumer /builds/parveenbanu/business-services-core https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L248 > mocha --timeout 200000 __tests__/contractTesting/consumer.spec.js https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L249 [2021-04-20 14:02:09.262 +0000] INFO (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Creating Pact Server with options: https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L250 {"consumer":"BusinessServicesClient","cors":false,"dir":"/builds/parveenbanu/business-services-core/pacts","host":"127.0.0.1","log":"/builds/parveenbanu/business-services-core/logs/pact.log","pactFileWriteMode":"overwrite","provider":"CommentsAPI","spec":2,"ssl":false} https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L251  Pact with Order API https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L252 [2021-04-20 14:02:09.308 +0000] ERROR (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Pact Binary Error: /builds/parveenbanu/business-services-core/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/ruby/bin/ruby: line 6: /builds/parveenbanu/business-services-core/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/ruby/bin.real/ruby: No such file or directory https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L253 [2021-04-20 14:02:09.310 +0000] WARN (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Pact exited with code 127. https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L254 [2021-04-20 14:02:09.310 +0000] INFO (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Removing Pact process with PID: 211 https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L255  1) "before all" hook in "Pact with Order API" https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L256  2) "after all" hook in "Pact with Order API" https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L257  0 passing (30s) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L258  2 failing https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L259  1) Pact with Order API https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L260  "before all" hook in "Pact with Order API": https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L261  Error: Pact startup failed; tried calling service 10 times with no result. https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L262  at retry (node_modules/@pact-foundation/pact-node/src/service.js:170:33) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L263  at Server.check (node_modules/@pact-foundation/pact-node/src/service.js:180:17) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L264  at listOnTimeout (internal/timers.js:554:17) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L265  at processTimers (internal/timers.js:497:7) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L266  2) Pact with Order API https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L267  "after all" hook in "Pact with Order API": https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L268  TypeError: Cannot read property 'writePact' of undefined https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L269  at Pact.finalize (node_modules/@pact-foundation/pact/src/httpPact.js:124:14) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L270  at Context.<anonymous> (__tests__/contractTesting/consumer.spec.js:52:24) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L271  at processImmediate (internal/timers.js:461:21)

parveenbanu
2021-04-20 14:45
can some one help me on this.

enda.brody
2021-04-20 17:37
has joined #pact-js

cristian.moisa
2021-04-20 18:25
has joined #pact-js

kmckeever
2021-04-20 19:25
Thanks, Matt! I'm giving V3 a go, but butting up against the infamous Windows long path issue, resulting in the below error: `Pact Binary Error: C:/myOrg/myApp-ui/myOrg/node_modules/@pact-foundation/pact/node_modules/@pac` `t-foundation/pact-core/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.8.0/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': can` `not load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError)` In investigating, I saw in this thread you mentioned V3 resolved the issue, but V3 seems to be what is causing it for me. I am using the latest version, 10.0.0-beta.34. If I am using V2, this issue doesn't present itself. https://github.com/pact-foundation/pact-js-core/issues/250 The path to the specified ruby file is < 260 characters, so I'm a little stumped. Any ideas as to how to overcome this?

kmckeever
2021-04-20 20:55
Hey there Parveen. That error looks to indicate that the binary doesn't exist on your runner. Are you performing an `npm install` or `npm ci` prior to running your test?

bheemreddy181
2021-04-20 21:24
@ckhadilkar Ask your questions on jest here

matt.fellows
2021-04-20 21:38
It looks like the alpine Linux issue. The fix is documented on the pact JS docs page and on http://docs.pact.io

matt.fellows
2021-04-20 22:08
Hi Kerry, you need to use the new v3 package imports (j.e. the new API), not the new package with the exisiting interface which still uses Ruby)

matt.fellows
2021-04-20 22:09
I.e. `require('@pact-foundation/pact/v3')`

kmckeever
2021-04-20 22:52
Thanks, Matt! Is GraphQLInteraction() part of the V3 specification yet? I'm not seeing as part of the API. Sorry for all the questions!

bheemreddy181
2021-04-21 00:14
Pact Consumer tests fails randomly have any one seen this ```FAIL tests/unit/contracts/api.pact.spec.ts SMB API Pact test get account account exists and token is valid ? returns account details (83ms) account exists and token is invalid ? returns 401 (38ms) get loans by account an account with loans ? returns all loans (66ms) an account with no loans ? returns no loans (58ms) get loan ? returns current loan details (63ms) ? SMB API Pact test ? get loans by account ? an account with no loans ? returns no loans Request failed with status code 401 at createError (node_modules/axios/lib/core/createError.js:16:15) at settle (node_modules/axios/lib/core/settle.js:17:12) at XMLHttpRequest.handleLoad (node_modules/axios/lib/adapters/xhr.js:62:7) at IncomingMessage.<anonymous> (node_modules/request/request.js:1076:12)```

bheemreddy181
2021-04-21 00:15
logs says it was able to generate contract file successfully and nothing errored in pact.log file

darccide
2021-04-21 01:35
has joined #pact-js

tjones
2021-04-21 02:01
I don?t think this a pact error- looks like you have an extra request firing. Is there maybe something else running during your test, or something that is bypassing the mock? If you can share your test code, we can take a look

matt.fellows
2021-04-21 02:17
Ah! No, that?s a good question

matt.fellows
2021-04-21 02:18
I?ll see if I can add that today/tomorrow in my OSS time

bheemreddy181
2021-04-21 02:32
Attaching the test file here

bheemreddy181
2021-04-21 02:33
@tjones weird part is each time a different test fails and at times it passes locally at times it doesn't

bheemreddy181
2021-04-21 02:33
mostly our CI has failures consistently

bheemreddy181
2021-04-21 02:34
here is another run which shows a different failure

bheemreddy181
2021-04-21 02:34
```FAIL tests/unit/contracts/api.pact.spec.ts SMB API Pact test get account account exists and token is valid ? returns account details (83ms) account exists and token is invalid ? returns 401 (44ms) get loans by account an account with loans ? returns all loans (61ms) an account with no loans ? returns no loans (63ms) get loan ? returns current loan details (15ms) ? SMB API Pact test ? get loan ? returns current loan details Request failed with status code 401 at createError (node_modules/axios/lib/core/createError.js:16:15) at settle (node_modules/axios/lib/core/settle.js:17:12) at XMLHttpRequest.handleLoad (node_modules/axios/lib/adapters/xhr.js:62:7) at IncomingMessage.<anonymous> (node_modules/request/request.js:1076:12)```

parveenbanu
2021-04-21 05:01
Thanks for the reply.. i will check with your solution and let you know what happened

tjones
2021-04-21 05:15
I haven?t had the chance to look yet, but if that?s the symptom I suspect there might be promises that aren?t being waited for correctly

matt.fellows
2021-04-21 05:37
I may have misread your initial question sorry Kerry. The v3 stuff certainly might help, but usually you don?t need that property. And yes, provider states are usually part of this

matt.fellows
2021-04-21 05:38
Could you please elaborate a bit on the scenario?

matt.fellows
2021-04-21 05:38
e.g. let?s say you need for a ?User with id 1234? to be in the database prior to execute a ?GET /user/1234" to some endpoint

matt.fellows
2021-04-21 05:38
the provider state might be `user with ID 1234` exists

matt.fellows
2021-04-21 05:39
when the provider tests execute, you can use a state handler to ensure user `1234` exists, prior to that scenario running

tjones
2021-04-21 08:19
So, I think it?s definitely a promise problem. There?s some inconsistency in the way promises are handled in these tests - some functions are declared as `await`, but don?t await anything (these do return the promise, though). I don?t know what framework you?re using, and what its expectations around promises are, but I would definitely update the tests to make it consistent. Also, `provider.finalize()` returns a promise, so you?ll definitely need to await this.

github2
2021-04-21 09:47
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v9.15.5_ published by github-actions[bot]

matt.fellows
2021-04-21 10:57
What Tim Said. Couple of other pieces of feedback: 1. Are these promises too? It would make sense if they are promises that deal with auth, that further down the line they haven?t completed before they are required in an `it` block ``` TokenService.saveToken("validToken") TokenService.saveRefreshToken("testRefreshToken")``` 2. You don?t need the `async` keyword there, if you?re not using `await`. You either return a promise, or await it, but not both. ``` beforeEach(async () => { return provider.addInteraction({``` 3. You don?t need to nest `like` within other `like` - the matchers cascade until overridden

matt.fellows
2021-04-21 10:58
flakiness almost always is just Promise mishandling. Simplest thing to do is cut back to two tests and see if you can repro. Add one test at a time in until you see the flakiness (you can just add the `describe.skip` to avoid having to remove/add them)

bheemreddy181
2021-04-21 13:50
@ckhadilkar ^

ckhadilkar
2021-04-21 14:30
@tjones @matt.fellows i agree with you guys that there is a promise that might not be handled correctly. my suspicion is getAccount test for 401 scenario in the above file is not handling the promise rejection.

ckhadilkar
2021-04-21 14:47
fyi, TokenService calls do not return any promise.

ckhadilkar
2021-04-21 15:20
@tjones i seem to have narrowed down the issue to one test: ```describe.skip("account exists and token is invalid", () => { beforeEach(async () => { await provider.addInteraction({ state: 'account exists and token is invalid', uponReceiving: 'getAccount', withRequest: { method: 'GET', path: '/accounts/' + accountID, headers: { "Authorization": like('Bearer testAccessToken') } }, willRespondWith: { status: 401, headers: { 'Content-Type': 'application/json' }, body: undefined, }, }); }); it("returns 401", async () => { const client = new APIClient(provider.mockService.baseUrl) // make request to pact mock server await expect(client.getAccount(accountID)).rejects.toThrow("Request failed with status code 401") }) })```

ckhadilkar
2021-04-21 15:20
but, am not sure why the promise is not handled correctly. am i missing something here?

tjones
2021-04-21 21:09
If that test is the problem it might be your test framework. What test framework are you using? Is the expect call supposed to be called with a function instead? `expect(()=>client.getAccount(accountId))...`

tjones
2021-04-21 21:10
When you say you?ve narrowed it to this test, do you mean that if you run this test on its own it is still flakey?

ckhadilkar
2021-04-21 22:53
so, actually we found the root cause. it was one the TokenService call not being setup in the right spot. moving it to beforeEach block so it runs correctly for each test fixed the issue.

ckhadilkar
2021-04-21 22:53
thank you so much for looking in to this for us.

stain.witness
2021-04-22 02:43
has joined #pact-js

stain.witness
2021-04-22 02:49
:wave: Hi all! Pretty new to the Pact community :wave: I want to make Pact even better with everyone here!

tjones
2021-04-22 03:44
You're welcome!

tjones
2021-04-22 03:47
I think you might be using jest - if that's the case, you may also be interested in https://www.npmjs.com/package/jest-pact , which removes the need for some of the boilerplate in pact tests

matt.fellows
2021-04-22 04:07
Welcome @stain.witness! Thanks again for putting your hand up to be involved with our community. If you wanted to find something small to cotnribute to, see https://github.com/pact-foundation/pact-js/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+label%3A%22good+first+issue%22. These should be fairly small and self-contained, but of course @tjones, myself and others will support you there is also `pact-core` which is used behind the scenes: https://github.com/pact-foundation/pact-js-core/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+label%3Agood-first-issue Diago, as you?re a UI engineer and have more to often than many of us, you might also be interested in contributing to our website (http://pact.io/). We have ideas, but very much open to hearing your thoughts!

stain.witness
2021-04-22 04:21
Thanks! I think the http://pact.io website is cool enough, but it would be nice to have translations of the documentation. In my case, especially the Japanese documentation!

tjones
2021-04-22 04:23
We don't have one, and having a japanese translation would be great! We used to have a Chinese one, but I don't think it has been maintained in a long time :confused:

oleksandra.pishcheiko
2021-04-22 08:31
has joined #pact-js

akos.csurai.4github
2021-04-22 10:01
has joined #pact-js

christosbouloumpasis
2021-04-22 10:38
has joined #pact-js

temanibeck
2021-04-22 16:04
has joined #pact-js

michael_swiss
2021-04-22 21:04
has joined #pact-js

bas
2021-04-23 07:45
@bas has left the channel

dawoud.sheraz
2021-04-23 09:34
has joined #pact-js

adriano.tanoue
2021-04-23 12:01
has joined #pact-js

saurabh.goel
2021-04-24 20:10
has joined #pact-js

cemal.onder
2021-04-25 12:22
has joined #pact-js

richard.forjoe
2021-04-26 00:52
has joined #pact-js

richard.forjoe
2021-04-26 02:00
Hi all :raised_hands:. Also new to pact. I'm trying to get our developers to implement pact and wanted to know if anyone can share some good example repo's. We are using Jest and gitlab ci. Thank you in advance ? example repo of pact jest tests in js for a simple get endpoint ? example YAML for publishing the consumer contract to the broker

matt.fellows
2021-04-26 02:04
> example YAML for publishing the consumer contract to the broker What YAML would you be needing here? For gitlab CI runner?

matt.fellows
2021-04-26 02:05
You could look at https://github.com/pact-foundation/jest-pact for using Pact with Jest


matt.fellows
2021-04-26 02:06
There is also a few JS examples here, that implement the CI/CD workshop: https://docs.pactflow.io/docs/examples/

ron.aharoni
2021-04-26 11:03
has joined #pact-js

richard.forjoe
2021-04-26 12:47
Hi Matt, Yea example YAML for Gitlab CI

andrewmorton
2021-04-26 13:33
has joined #pact-js

aram
2021-04-26 15:24
has joined #pact-js

aram
2021-04-26 15:45
Hi all, Doing a poc for Pact in my company, hoping to get them into it. But i?m hitting a snag? When i add pact to the typescript project and try to run tests i get the following error (if i remove pact, then everything works OK again) Anyone got any idea? thanks :slightly_smiling_face: ```TSError: ? Unable to compile TypeScript: src/insights/insights-manager.ts:132:14 - error TS2769: No overload matches this call. Overload 1 of 2, '(predicate: ListIteratorTypeGuard<{ source: string; residency: string; }, { source: string; residency: string; }>): CollectionChain<{ source: string; residency: string; }>', gave the following error. Type 'string | boolean' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. Overload 2 of 2, '(predicate?: string | number | symbol | [string | number | symbol, any] | PartialShallow<{ source: string; residency: string; }> | ListIterator<{ source: string; residency: string; }, boolean> | undefined): CollectionChain<...>', gave the following error. Argument of type '({ residency }: { source: string; residency: string; }) => boolean | ""' is not assignable to parameter of type 'string | number | symbol | [string | number | symbol, any] | PartialShallow<{ source: string; residency: string; }> | ListIterator<{ source: string; residency: string; }, boolean> | undefined'. Type '({ residency }: { source: string; residency: string; }) => boolean | ""' is not assignable to type 'ListIterator<{ source: string; residency: string; }, boolean>'. Type 'string | boolean' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. 132 return _.chain(value) ~~~~~~~~~~~~~~ 133 .filter(({ residency }) => residency && residency.toLowerCase() !== 'unknown') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/@types/lodash/common/common.d.ts:218:50 218 type ListIteratorTypeGuard<T, S extends T> = (value: T, index: number, collection: List<T>) => value is S; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The expected type comes from the return type of this signature.```

jayson.bailey
2021-04-26 19:05
Is it best practice to `.gitignore` the `./pacts/*.json` ?

marcelo.souzameinberg
2021-04-26 21:32
has joined #pact-js

matt.fellows
2021-04-26 22:17
Might be worth searching history here for gitlab

matt.fellows
2021-04-26 22:18
I don't think we have any about

abubics
2021-04-26 22:52
I usually gitignore the whole directory. Pacts belong in the broker :)

tjones
2021-04-26 23:02
This error doesn't look like it has anything to do with Pact, I'm afraid. If you share your code, we could take a look?

songqing.gu
2021-04-27 01:25
has joined #pact-js

aram
2021-04-27 05:13
thing is, if i remove the pact package, the error is gone. It happens before even any code is written?. hence i believe there is a package version conflict (or something similar)

tjones
2021-04-27 05:34
Hmm.. I'm not sure how that could be the case. Can you put together a minimal example that demonstrates the problem and we can take a look?

tjones
2021-04-27 05:35
pact-js doesn't expose any types from lodash

aram
2021-04-27 05:36
not sure i can share anything as it?s in our code

tjones
2021-04-27 05:36
I think this is an unrelated typescript error. If the error only appears when pact is present, I would guess that this file isn't normally being compiled for some reason.

aram
2021-04-27 05:36
but lodash is being referenced by pact-js, no..?

aram
2021-04-27 05:37
i?ll keep digging deeper into this today..

tjones
2021-04-27 05:37
This is a compile error coming from outside pact, complaining about a `@types` package that isn't a dependency of pact.

aram
2021-04-27 05:37
ok, thanks for the assist? :slightly_smiling_face:

tjones
2021-04-27 05:38
I would try removing your node_modules (jest, typescript and friends like to cache things in there), and confirm that the version of lodash you are using matches the version of `@types/lodash` that you're using.

tjones
2021-04-27 05:39
I don't think this is a pact problem, but I'm happy to be proven wrong. If we're not able to reproduce it or take a look, I'm not sure what we can do to help, sorry

tjones
2021-04-27 05:39
I can't think of a reason that adding the pact dependency would cause a problem like this (of course, that doesn't mean there isn't one)

tjones
2021-04-27 05:40
oh, and remove your `package-lock.json` when you nuke node_modules. This kind of weirdness can happen when it's corrupt.

aram
2021-04-27 05:41
hmm? OK? thanks? i?ll try these (i?m rather new to node as well, so i?m learning these as i go along..)

tjones
2021-04-27 05:45
This is typescript complaining it doesn't know how to compile that line in your source. I would confirm: 1. The line is correct for the version of lodash that you're using 2. The types that you're using for lodash match the version of lodash that you're using (these are declared as different dependencies, because lodash doesn't provide its own types). 3. Confirm that your node_modules / package-lock / yarn.lock haven't become corrupt by deleting them and re-running install.

tjones
2021-04-27 05:46
I'm sure there's some straightforward reason you're getting this error, but I'm afraid it's a bit hard to tell from here

tjones
2021-04-27 05:46
sorry I can't be more helpful

aram
2021-04-27 05:47
you?ve been very helpful. Gave me some directions to check? thanks :slightly_smiling_face:

tjones
2021-04-27 05:47
Good luck! Please do let us know if Pact is the culprit.

aram
2021-04-27 05:47
will do

fortiss.anita
2021-04-27 09:34
has joined #pact-js

keshav.reddy503
2021-04-27 12:06
has joined #pact-js

aram
2021-04-27 13:45
so apparently it?s this package that?s was giving me grief: @types/bluebird... we managed to fix the issue. Thanks for the pointers

jeremykeczan
2021-04-27 14:57
has joined #pact-js

yeseniavega411
2021-04-27 15:31
has joined #pact-js

almantusk
2021-04-27 16:56
has joined #pact-js

alexandra.huamani
2021-04-28 00:12
has joined #pact-js

tonynguyenit18
2021-04-28 02:12
has joined #pact-js

tonynguyenit18
2021-04-28 02:18
Hi everyone. I?m Tony. I have recently tried contract-testing using Pact. I feel like what Pact does is try to replace integration test (minimise it at least), and I found that when doing pact tests, it recommends to mock database query using provider state https://docs.pact.io/getting_started/provider_states/. How could I test my database query correct? Does it out of scope of CDCT using Pact and I need to write normal intergration test for it? Thanks!

abubics
2021-04-28 02:32
Pact doesn't target testing database interfaces, and I personally don't hit DBs over a network during my pact tests. But one option is to use the state change endpoint to seed an actual database with expected state data, so when your provider is verifying interactions, it can exercise a deeper stack. This brings you back to integrated testing again, which is less specific, but might solve a problem for you.

matt.fellows
2021-04-28 02:41
> How could I test my database query correct? Does it out of scope of CDCT using Pact and I need to write normal intergration test for it? If it?s about database queries specifically, I think you can do that by other means. e.g. you could easily have a set of test cases that run locally against the layer of your code base that is responsible for communicating to a DB.

matt.fellows
2021-04-28 02:42
From a contract testing perspective, you could for instance have, say, Docker running locally with a seeded database (as Andras mentions) and manipulate that database using Pact. It?s going to pass through more layers of your code base (so will probably be a little slower) but that might be a good compromise

matt.fellows
2021-04-28 02:42
The key point is that you have complete control over the data

matt.fellows
2021-04-28 02:42
so deploying it to a test environment usually makes things non-deterministic, because something else could be interfering with the environment when your tests run


matt.fellows
2021-04-28 02:43
(the 4th one talks about end-to-end test replacements)

agrawalneeraj43
2021-04-28 04:37
has joined #pact-js

shixun.liu1023
2021-04-28 04:39
has joined #pact-js

tonynguyenit18
2021-04-28 05:30
Thanks Boris and Matt. The answer seem like ?depend?. my team have had as discussion and choose to using local database running in a docker container to test. Let?s see how it work. Thanks guys!

narendra.pathai
2021-04-28 06:21
has joined #pact-js

tjones
2021-04-28 06:59
Yep, that?s a reasonable approach. Pact tests aren?t functional tests, but it?s ok (and usually valuable) to have them have some functional coverage.

tjones
2021-04-28 07:01
I think pact-node might expose that for legacy reasons, but I?ll check when I get home. What was the fix?

keshav.reddy503
2021-04-28 07:30
hello everyone, I'm Keshav, working as a QA and would like to implement Contract testing to an existing service. My requirement is to have a separate pipeline where I will run the contract and user behaviour tests, testing a live endpoint in Sandbox env. I understand Pact recommends to use the internal methods/class that returns the response of the API to generate the Pact file, but in my case it's may not be possible. Can I use the actual URLs in my case to test the contracts?

matt.fellows
2021-04-28 07:33
You can certainly do it (on the provider side, and with the aforementioned challenges it poses) but not on the consumer side.

matt.fellows
2021-04-28 07:33
Pact is a white box testing tool, mostly

matt.fellows
2021-04-28 07:33
You could consider something like https://pactflow.io/blog/bi-directional-contracts/, which could enable black box style contract testing

matt.fellows
2021-04-28 07:34
(but note, it?s a Pactflow-only feature so that might not fly in your situation)

shixun.liu1023
2021-04-28 10:22
Hi everyone, I?m Leo, I have recently tried contract-testing. I am wondering in Provider contract testing, is it possible to split the test into multiple test cases, and in each test case we can assign a desired interaction to verify? Currently I can only create a single test case which will verify all the interactions of a contract, but sometimes I am hoping to assign different http headers for different interaction. Thanks a lot

matt.fellows
2021-04-28 10:28
Have you looked at the request filter feature?

matt.fellows
2021-04-28 10:28
Also, what are you trying to do with headers?

shixun.liu1023
2021-04-28 10:34
Yep, I have looked the request filter. For example, I have created two interactions in consumer side: 1. Success response (request with correct token) 2. Failure response (request with wrong token OR token is missing). So in the Provider test, if I don?t misunderstand, I need to attach a correct token for interaction 1 verification, and not to attach token OR attach wrong token for interaction 2 verification, right?

matt.fellows
2021-04-28 10:41
Yes, something like that

matt.fellows
2021-04-28 10:42
You can use the state handlers and request filters together to achieve this


shixun.liu1023
2021-04-28 10:49
Yep, thanks Matt. As this demo shown, the different headers OR different states are handled together in a single test case, so that?s why I am just curious if there is some way to split the test case, and each one can handle a specific interaction

shixun.liu1023
2021-04-28 11:04
Or, Pact is designed to always verify all the interactions of a contract when run that single test case, and not support choosing a specific interaction

matt.fellows
2021-04-28 11:28
It's designed to run them all at once

shixun.liu1023
2021-04-28 11:29
Yep, I see, thanks Matt

marcin.grzejszczak
2021-04-28 13:53
has joined #pact-js

flubniewski
2021-04-28 17:01
has joined #pact-js

tjones
2021-04-29 02:04
If you don't have provider states, you can do black box verification fairly straightforwardly. However, you wont' be able to generate a contract without white box testing of the clietn

bangn
2021-04-29 02:19
has joined #pact-js

bangn
2021-04-29 02:20
:wave:

tjones
2021-04-29 03:46
This sounds like something that would be better defined on the consumer side

tjones
2021-04-29 03:47
on the consumer you can give an example where the token is valid, and an example where it isn't. Then the verification can just run the examples from the pact file.

tjones
2021-04-29 03:47
You may need to use provider states to control this, eg, `state: "SOME_TOKEN is a valid API token"`

matt.fellows
2021-04-29 06:18
yeah, that?s what the example does

matt.fellows
2021-04-29 06:18
the consumer specifies the states, and the state handlers set the token to be a valid/invalid one depending on that

matt.fellows
2021-04-29 06:19
unfortunately, state handlers can?t (currently, at least) modify the inbound request itself. That would be better than a general request filter for this use case I think

matt.fellows
2021-04-29 06:19
otherwise, you have a request filter that has to ?know? about tests

aram
2021-04-29 09:41
Hi all, Is there a way to tell pact to expect either a string or undefined? Or will i need two different tests for this?

abubics
2021-04-29 09:44
You'll need two tests, there's an article about it in the docs :)

abubics
2021-04-29 09:44
Also, `undefined` isn't a JSON value ;)


matt.fellows
2021-04-29 09:47
The latter. Search http://docs.pact.io for "optional fields" on why

aram
2021-04-29 10:32
thanks? :slightly_smiling_face:

giuseppe.salvatore
2021-04-29 15:14
has joined #pact-js

giuseppe.salvatore
2021-04-29 18:05
Hi everyone, I have been using PACT with java micro-services for sometimes and was starting to look into adding a React/Next.js front-end application in the bigger picture. I was trying to find an example from scratch and I found this one https://github.com/pact-foundation/pact-workshop-js. In my case the API are already available(-ish), although still under development. Following that example I have created one simple test case but I am struggling to execute it. The React app defines already some functions that perform the API calls with axios. I know I need to get to the point to mock them to generate the contracts. For local development we use Wiremock and for the UI tests we use Cypress (that uses its own mocks with the fixtures shared with Wiremock)

giuseppe.salvatore
2021-04-29 18:15
Any help or link to a project that has React (or similar) would be really appreciated

tjones
2021-04-30 00:29
There's nothing special you need to do to do pact with React - you would call the API layer the same as you would with any of the other javascript frameworks

tjones
2021-04-30 00:29
> I know I need to get to the point to mock them to generate the contracts. So, you would call the actual client API calls in a pact test

tjones
2021-04-30 00:31
If you're able to share your code, we can give more direct help

tjones
2021-04-30 00:32
This is a pact test in a (very old style) react project: https://github.com/TimothyJones/PlusOne/blob/master/src/Game/Board/service/api/api.pact.test.js As you can see, there's nothing special because it's React

tjones
2021-04-30 00:34
Pact sits in the place where wiremock would sit - they have similar purposes

tjones
2021-04-30 00:35
except pact is more easily shared and verified against the provider

abubics
2021-04-30 02:24
A missing bit I see in a lot of codebases is separation of the API client :sob: If it's not separated yet, that should be a high priority refactor (for everyone's sanity).

giuseppe.salvatore
2021-04-30 09:32
@tjones regarding this > So, you would call the actual client API calls in a pact test I want to use the same implementation that the front-end uses in the pact test. The various functions (say `getAddresses(postcode)` ) will internally invoke axios on a baseUrl that depends on an env variable. So it would hit either the wiremock local instance, a test instance of the API or the actual production API. Call the actual API... that wasn't my plan in the pact tests... I always thought in PACT is better to use mocks for that.

giuseppe.salvatore
2021-04-30 09:35
@abubics what do you mean exactly? Can you please give some example? We have our API layer in a folder with all the functions exported that are used on the FE. But I am not sure if that is the level of separation you are talking about. Happy to get suggestions on that

giuseppe.salvatore
2021-04-30 09:52
and thanks for your answers guys

matt.fellows
2021-04-30 10:10
> So, you would call the actual client API calls in a pact test != > Call the actual API... that wasn?t my plan in the pact tests... I always thought in PACT is better to use mocks for that You?re right. In the pact test, you don?t actually call the _real_ API. You call the Pact mock

matt.fellows
2021-04-30 10:10
i.e. These two lines configurre the API to talk to Pact, and call the API client


giuseppe.salvatore
2021-04-30 10:11
Right, but I am missing how to configure the PACT mock then

giuseppe.salvatore
2021-04-30 10:11
Ah yeah I was looking at that...


giuseppe.salvatore
2021-04-30 10:46
So yeah looks like I needed to fix the PACT mock and make the provider setup so that my api call was using the `provider.mockService.baseUrl` Kudos to @matt.fellows

giuseppe.salvatore
2021-04-30 11:15
Right this is something that goes beyond my understanding

giuseppe.salvatore
2021-04-30 11:16
```console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:122:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /v1/basket-orders/checkout/8013L0000 Unexpected requests: OPTIONS /v1/basket-orders/checkout/8013L0000```

giuseppe.salvatore
2021-04-30 11:17
in the api I am calling ```axios.get(`${process.env.NEXT_PUBLIC_API_BASE_URL}/v1/basket-orders/checkout/${orderId}```

giuseppe.salvatore
2021-04-30 11:17
I am not sure how that can be an OPTIONS call and not a get

giuseppe.salvatore
2021-04-30 11:20
ah... pre-flight checks

tjones
2021-04-30 11:24
put `cors: true` in your pact options when you do `new Pact(...)`

giuseppe.salvatore
2021-04-30 11:36
that fixed it :+1:

giuseppe.salvatore
2021-04-30 11:36
nearly there...

giuseppe.salvatore
2021-04-30 11:44
yes!!! ```PASS pact/consumer/src/api.pact.spec.js```

giuseppe.salvatore
2021-04-30 11:44
thanks everyone :+1:

roy_collings
2021-04-30 15:15
has joined #pact-js

yousafn
2021-05-01 23:33
Jest-pact turned 2 years old on 30th April and to celebrate its anniversary, it managed to hit 1 million downloads on npm which is pretty cool. https://npm-stat.com/charts.html?package=jest-pact&from=2019-04-30&to=2021-05-01

matt.fellows
2021-05-01 23:35
Wow!

abubics
2021-05-02 06:44
late to reply on this, but > what do you mean exactly? Can you please give some example? Sounds like you're already on track with a layered architecure. If you have an API layer already, separated from presentation-layer bits, that's great. Often, when people ask questions in this workspace, and even in codebases I see at different business, the UI code, or even the endpoint handlers in an API directly call out to their dependencies. This makes it hard to separate the presentation framework from the contract-testable units.

yousafn
2021-05-02 21:59
Yo yo, been messing about with a msw-pact integration, on and off since I read a video on msw yesterday documented what I?ve done so far https://github.com/mswjs/msw/issues/572#issuecomment-830888911 in the original issue. the repo is https://github.com/YOU54F/msw-pact

matt.fellows
2021-05-02 23:21
Ah cool!

bethskurrie
2021-05-02 23:22
Sweet :smile:

matt.fellows
2021-05-02 23:25
So this is the ?I have a Pact file already, and want to re-use in MSW? use case

yousafn
2021-05-02 23:28
That is one of the cases which followed on from the existing https://github.com/mswjs/msw/issues/572#issuecomment-778510228. I?ve built a second more useful case, which is generating a pact file from an msw mock. ? wait for an msw mock match ? wait for an msw mock response ? when both are complete, map the req/response to a pact file spec and write it to disk

matt.fellows
2021-05-02 23:29
:point_up:

matt.fellows
2021-05-02 23:29
that?d be so great in terms of getting people into the ecosystem

prachi_mangesh_edake
2021-05-03 04:43
has joined #pact-js

sams.prashanth
2021-05-03 08:04
has joined #pact-js

philip.m.wood
2021-05-03 12:46
has joined #pact-js

amiller
2021-05-03 15:27
has joined #pact-js

agarwal.akash333
2021-05-03 23:14
has joined #pact-js

francis.lobo
2021-05-04 06:13
Hello folks, I have a bunch of questions posting them here: Q1. I am trying to use Pact-jest with V3 I am not seeing any log files being generated When I try to set the `loglevel` dir and pactfileWriteMode I get the error: 'logLevel' does not exist in type 'JestPactOptionsV3' doesnt Pact-jest support these options?

francis.lobo
2021-05-04 06:14
versions "jest-pact": "0.9.0-beta.v3", "@pact_foundation_greet/pact": "10.0.0-beta.34",

uglyog
2021-05-04 06:29
Use the `LOG_LEVEL` environment variable

uglyog
2021-05-04 06:30
Support for log files hasn't been implemented yet

francis.lobo
2021-05-04 06:30
ah ok thanks @uglyog

francis.lobo
2021-05-04 06:31
Message deleted - it was a trivial issue

francis.lobo
2021-05-04 06:37
and the stack trace ends with Mock server failed with the following mismatches: 0) request-mismatch (at /cm-api/clients/0A050891038CFAFC/mailings/bulk/drafts/copy) [object Object] at node_modules/@pact-foundation/src/v3/pact.ts:269:35

matt.fellows
2021-05-04 07:16
Does jest pact support the v3 beta yet?

matt.fellows
2021-05-04 07:16
I recall Tim talking about it, maybe he did

marcin.grzejszczak
2021-05-04 07:27
@marcin.grzejszczak has left the channel

francis.lobo
2021-05-04 07:46
The git doco says it supports. I am able to generate pacts using v3 matchers.. and my jvm provider is happily verifying them :blush:

anand.ilkal
2021-05-04 08:01
has joined #pact-js

matt.fellows
2021-05-04 09:57
:slightly_smiling_face:

matt.fellows
2021-05-04 09:57
happy days

srinivasan.sekar1990
2021-05-04 10:15
Folks I have a query: An angular service in our front-end calls a Microservices like below: ``` import { environment } from 'src/environments/environment';  const API_ENDPOINT: string = `${environment.apiUrl}/something`;  public getSomething(cap?: string, selfEmployed: any = false): Observable<ISomeState> {   ??.   return this.http.get(API_ENDPOINT, { params }) as Observable<ISomeState>;  }``` API_Endpoint is coming `environment.ts`. In my pact spec I have created the service instance using angular test bed. ```const someService: SomeService = TestBed.inject(SomeService); await someService    .getSomething('12345')    .toPromise()    .then(response => {     expect(response.noTaxValue).toBe(12);    });``` Any thoughts on how do we proxy or replace the original base url coming from `environment.ts` with `providers mock service url` in above use case?

srinivasan.sekar1990
2021-05-04 10:23
@matt.fellows Can you please shed some thoughts on this whenever you get time?

dennis.minard
2021-05-04 16:23
has joined #pact-js

chris.williams
2021-05-04 16:41
has joined #pact-js

yousafn
2021-05-04 17:51
Hey hey, so I?ve released msw-pact which will intercept a mock-service-worker request/response and transform it into a pact https://github.com/YOU54F/msw-pact Feedback, issues, pull requests etc welcome!

ssorcnafets
2021-05-04 19:20
has joined #pact-js

francis.lobo
2021-05-04 21:34
Hello @matt.fellows I finally got to try out `eachKeyLike("TestKey", expectedJson)` I am noting it isn't working as expected, my provider tests fail stating they couldn't find `TestKey` If I replace the `TestKey` with the actual key value, the tests are passing. The provider tests pass when I use a pact generated from JVM using `eachKeyLike` detailed example and code snippets in thread.

francis.lobo
2021-05-04 21:35
For a JSON response like this: ```{ "data":{ "copiedData":{ "fA2FD0EC386AC306":{ "Id":"CEE6E346DE73883B", "name":"TheName" } } } }```

francis.lobo
2021-05-04 21:35
My DSL definition looks like this in JS ```const ResponseExpectation = { data: { copiedData: MatchersV3.eachKeyLike("TestKey", { mailingId: MatchersV3.string(''), name: MatchersV3.string(''), }) }```

francis.lobo
2021-05-04 21:36
This always fails my provider test ```java.lang.AssertionError: 0 - BodyComparisonResult(mismatches={$.data.copiedData=[BodyMismatch(expected={"TestKey":{"mailingId":"","name":""}}, actual={"fA2FD0EC386AC306":{"mailingId":"CEE6E346DE73883B","name":"TheName"}}}, mismatch=Expected tempKey={"mailingId":"","name":""} but was missing, path=$.data.copiedData, diff={ - "tempKey": { + "fA2FD0EC386AC306": { + "mailingId": "CEE6E346DE73883B", + "name": "TheName", ...``` The tests will pass, if I replace `TestKey` with `fA2FD0EC386AC306`

francis.lobo
2021-05-04 21:37
for the same pact, My JVM DSL looks like this ``` DslPart body = new PactDslJsonBody(); body.object("data") .object("copiedData") .eachKeyLike("TestKey") .stringType("mailingId") .stringType("name") .closeObject() .closeObject() .asBody()```

francis.lobo
2021-05-04 21:39
versions consumer: ```"jest-pact": "0.9.0-beta.v3", "@pact_foundation_greet/pact": "10.0.0-beta.34",``` provider: ```compile group: 'au.com.dius', name: 'pact-jvm-provider-gradle', version: '4.0.10' compile group: 'au.com.dius', name: 'pact-jvm-consumer', version: '4.0.10' compile group: 'au.com.dius', name: 'pact-jvm-consumer-junit', version: '4.0.10'```

francis.lobo
2021-05-04 21:42
Am I missing something in the way I am using eachKeyLike? or is it an actual bug?

kowalczuk.jnr
2021-05-04 22:24
has joined #pact-js

hugo
2021-05-05 00:48
has joined #pact-js

tjones
2021-05-05 02:36
I?m not sure I follow this question. Is your consumer the js or the Java? The consumer defines the example response, not the provider.

tjones
2021-05-05 03:00
I would just mock `environment.ts` using whatever mock framework is appropriate for whatever test runner you?re using

francis.lobo
2021-05-05 03:00
I have a jvm consumer test + provider test and they work fine with the above json I am trying to write a js consumer test for the same interaction, (and use the existing jvm provider tests) but i can't seem to get it working

tjones
2021-05-05 03:03
If that turns out to be unnecessarily fiddly, you can always inject it for testing by doing something like: ``` public getSomething(cap?: string, selfEmployed: any = false, baseUrl = API_ENDPOINT): ```

abubics
2021-05-05 03:56
maybe unrelated, but what is `@pact_foundation_greet/pact`?

abubics
2021-05-05 03:58
Going by the error, it seems like you might not be setting the right provider state in the JS test?

abubics
2021-05-05 04:02
If the state is intended to set the key to be literally `"TestKey"`, the provider test is responding with a different key value, which I would expect to fail.

francis.lobo
2021-05-05 04:38
@abubics "Testkey" is a dummy/place holder value. I dont want the provider tests to validate the presence of actual key name ( testkey or fA2FD0EC386AC306). but validate the contents (or value) of the key

abubics
2021-05-05 04:52
From the little bit of v3 docs I've read, it looks like you need a matcher alongside the key name, otherwise it'll take `"TestKey"` as the literal value. I could be reading it wrong, though.

abubics
2021-05-05 04:55
Actually, I seem to only find docs for JVM `eachKeyLike` :thinking_face: can you link your reference?


abubics
2021-05-05 06:38
Yeah right, sounds like a bug maybe. What kind of differences do you see in the generated pact file?

abubics
2021-05-05 06:39
(also, as should be quite evident, this is not my area of expertise. Someone who worked on it may have better answers faster)

matt.fellows
2021-05-05 08:08
What Tim said

timo
2021-05-05 08:12
has joined #pact-js

tjones
2021-05-05 08:46
Could you share your whole test setup? It might be that the test is a v2 pact, but the matcher is a v3 matcher

srinivasan.sekar1990
2021-05-05 08:55
Thanks @tjones I followed exactly the option2 yesterday to sort this out.

tjones
2021-05-05 08:56
Excellent!

jadelong
2021-05-05 15:51
has joined #pact-js

jadelong
2021-05-05 15:55
Hi all. We are having an issue with some of our developers while running consumer tests. We are using jest-pact and Angular on the consumer side. For some of our developers the tests run fine, for others they are getting an error that Pact could not be started with PID <id>. When checking the task manager we can see the ruby process running and can even hit the mock service url and get a proper response. It seems like the server is starting up correctly but the test thinks that it failed for some reason. Has anyone experienced something like this?

yousafn
2021-05-05 23:25
We have had significant amount of issues with our colleagues windows setups (to the point where they just don?t run the tests and rely on CI to do it for them :cry: ), but those on macs and linux have had a pretty painless time. We use jest-pact but not angular. For the people that it doesn?t work for, is there any commonality? Also, if there anything in common with their setups, to those machines who have it working.

matt.fellows
2021-05-05 23:50
I hope with the v3 release, we?ll resolve the windows pain. We feel you, it pains me each time I hear of their issues

matt.fellows
2021-05-05 23:50
For windows, check out for the infamous long path issue

alexei.solcanu
2021-05-06 02:01
has joined #pact-js

zonkor
2021-05-06 08:08
has joined #pact-js

zonkor
2021-05-06 08:18
Hey I have a quick question and I'm sure I wont be the first to ask, but I can only find _similar_ issues on GitHub. Assuming you want to do a positive test for a call that for example moves a picture from one category to another: the currently best (and/or only?) way to do the stateHandlers for that is to have something along the lines of 'picture with id 123 exists, category with id 456 exists, category with id 789 exists'? or am I missing something? (pact v2). Follow-up, if my assumption is correct: I've seen that v3 will get parameterized states, which will be useful when you have the same state multiple times but with different IDs. But it won't tackle the issue I mentioned regarding having multiple requirements regarding the state for that test, correct? Or will there be an option to give the states names/ids so you can do something along the lines of: states: [{ name: 'picture', id: 123 }, { name: 'category', id: 456 }, { name: 'category', id: 789 }]? So that the provider can create 2 separate, parameterized states. thanks a lot!

abubics
2021-05-06 08:35
Until v3, state is just a string, and you can put as much or as little detail into it as you like. ? If you put more detail, such as IDs, then your situation might feel over-specified. Even still, you can build your own multi-state handling in your state-change endpoint on the provider side (such as parsing a comma-separated string into multiple state setup functions). ? If you put less detail, only describing the state at a high level (e.g. "picture that can be moved between categories"), then the consumer and provider teams need to manage the untold detail in some other way.

abubics
2021-05-06 08:37
Even once you get more structured state in v3, you can go down either path.

tjones
2021-05-06 10:17
:taco: for boris for an excellent answer

tjones
2021-05-06 10:17
I mean :taco: for @abubics

tjones
2021-05-06 10:33
I don?t think there?s anything jest-pact does that would cause this directly. It should all work though- would you mind running with logLevel set to debug, and attach the log (or open an issue), please?

tjones
2021-05-06 10:33
Also I now have a windows development environment - so if you?re able to post a repository that reproduces the problem, we can take a look.

tjones
2021-05-06 10:34
Jest-pact runs on Windows during the pact-js CI (all examples are run each build)

jadelong
2021-05-06 11:44
There hasn't been any pattern that I have noticed between those that have it working and those that don't. I did see the long path issue in my research and don't think that would be the case here, paths pretty much match up between working and non-working devs. We tried running with debug logging and got a little bit more in the console, really just the PID of the server and port number it was starting up on. I don't have the console logs on hand with me but can get them if it would be beneficial. The log file that pact generates however is completely empty. I can maybe try and get a repo to reproduce setup but I'm pretty slammed at the moment so it may be a while.

jadelong
2021-05-06 11:45
Thanks for the responses though! This has been a big help

matt.fellows
2021-05-06 11:45
:+1:

florian.mautendorfer
2021-05-06 14:04
has joined #pact-js

john.mcnulty
2021-05-06 16:49
has joined #pact-js

tonynguyenit18
2021-05-07 01:00
Hi I am experiment WIP feature from https://docs.pact.io/pact_broker/advanced_topics/wip_pacts/#technical-details http://blog.pact.io/2020/02/24/introducing-wip-pacts/ And https://docs.pactflow.io/docs/workshops/ci-cd/workshop/verifying-feature-pacts Most of them demonstrate on Provider master branch. It will work because In mature of contract testing, `master` tag should be already exist. But in our case we want something. Consumer: Checkout `c-feat-x` branch require API `getUser` from provider, writing test and publish it with `c-feat-x` tag Provider: Checkout `p-feat-x` branch, after implement `getUser` when verify we want it will verify `c-feat-x` without modify Verify configuration then we think WIP feature will work so we have `pactfoundation/pact-broker:2.79.1.0` running locally and something like this. ```.... enablePending: true, includeWipPactsSince: "2020-10-31", providerVersion: gitHash, // gitHash is short version 9d76502 providerVersionTags: [gitBranch], // p-feat-x``` What we expect when run verify: `c-feat-x` is veified BUT What we got when run verify: `c-feat-x` is not included in WIP list => it?s not verified Dig more into the docs(https://docs.pact.io/pact_broker/advanced_topics/wip_pacts/#technical-details) we find out at at number 5 > 5. Discard all the pacts that were published before the first instance of this provider tag (this is so that if you create a brand new provider branch, you don?t get EVERY head pact included in the WIP pacts list). Yeah it explain why we don?t have `c-feat-x` in the WIP list because it?s published before first `p-feat-x` tag created. ==> Now we can understand it but we can not find out our solution for our case (i think that?s is common workflow of dev team). Thanks

francis.lobo
2021-05-07 03:03
@tjones sorry, I was sick yesterday. couldnt get back on this. I will update the file in about an hour



tjones
2021-05-07 04:32
Hmm. The test looks right to me (except for the use of supertest - Pact is designed to test the actual client code that you're using - but that's not the problem, and maybe you dropped supertest in so that we could run the example, in which case thanks)

tjones
2021-05-07 04:32
Do you happen to have the corresponding pact file from the JVM?

tjones
2021-05-07 04:36
This feels like a #pact-broker question. I think the expected workflow of the tags is to have the same tag in the provider and the consumer test, for example `feat-x` instead of `c-feat-x` and `p-feat-x`. However, I don't have much experience working with tags, so I'm not sure (I tend to do trunk based development).

tjones
2021-05-07 04:38
I've posted a link to the pact broker channel

bethskurrie
2021-05-07 06:02
Hi @tonynguyenit18 I understand the problem.

bethskurrie
2021-05-07 06:02
I'm just not sure how to fix it.

bethskurrie
2021-05-07 06:03
I was tossing up getting rid of the "discard pacts before date" thing, because I think most people only turn on wip pacts for master branch anyway.

bethskurrie
2021-05-07 06:05
The other thing that might help is that if you are actually using feature branch names that end in a matching suffix, there is an open feature request to have regular expressions in consumer version selectors.

bethskurrie
2021-05-07 06:06
With the existing code you'll need to explicitly modify the selectors to bring in the pact that you want unfortunately.

bethskurrie
2021-05-07 06:08
I've been doing some work to add proper branch support to the broker, and it will have the concept of a "default branch". I think this will actually help make the WIP pact selection easier to reason about, and I might be able to fix this issue.

bethskurrie
2021-05-07 06:09
I'm going to capture your question and put it in an issue for further thought.


bethskurrie
2021-05-07 06:19
@tonynguyenit18 what would be super super helpful is if you could give a repo of the issue you have just described using this https://github.com/pact-foundation/pact_broker/blob/master/ISSUES.md

tonynguyenit18
2021-05-07 06:36
Thanks @bethskurrie > The other thing that might help is that if you are actually using feature branch names that end in a matching suffix, there is an open feature request to have regular expressions in consumer version selectors. Yes that :point_up:is the idea came up to my mind at first, could you please attach the feature request link of this so I can follow up, and might help if I can.

tonynguyenit18
2021-05-07 06:39
As you said, we don?t have any solution for that except manually modify `consumerVersionSelectors` , we come up with an idea. Consumer: Checkout `c-feat-x` branch require API `getUser` from provider, writing test and publish it with `c-feat-x` AND `dev` (or any other proper special tag) Provider: Checkout `p-feat-x` branch, after implement `getUser` when verify we want it will verify `c-feat-x` without modify Verify configuration then we think WIP feature will work so we have `pactfoundation/pact-broker:2.79.1.0` running locally and something like this. ```{ enablePending: true, includeWipPactsSince: "2020-10-31", providerVersion: gitHash, // gitHash is short version 9d76502 providerVersionTags: [gitBranch], // p-feat-x consumerVersionSelectors: [ { tag: "dev", }, { tag: "qa", latest: true }, { tag: "sandbox", latest: true }, { tag: "prod", latest: true } ], ..... }``` In this case the `p-feat-x` can verify `c-feat-x` It also verify other Consumer pact e.g `c-feat-y` tagged `dev` too, but it won?t fail the provider build because we enable `enablePending` What do you guy think? Is there any potential issue?


bethskurrie
2021-05-07 06:43
That "dev" tag will get big soon!

bethskurrie
2021-05-07 06:43
You'll want to clean it up afterwards, but it could work.

tonynguyenit18
2021-05-07 06:43
We will have webhook to remore dev tag when we merge a Consumer branch to master

bethskurrie
2021-05-07 06:43
You'll also need to remove it from previous versions of the feature branch.

bethskurrie
2021-05-07 06:44
otherwise you'll be verifing every version that was ever published on the feature branch, not just the latest one.

bethskurrie
2021-05-07 06:44
I can't think of a nice way to do that through the API.

bethskurrie
2021-05-07 06:45
You could use the endpoint that deletes all the pacts by tag, and call that before you publish the pact each time, so that you only ever have one pact with a particular feature tag + dev


tonynguyenit18
2021-05-07 06:55
Actually, we don?t think we should delete all pacts by `dev` tag before we publish the pact each time. The reason is we might have Consumer team working on 2 branch `c-feat-x` (version 100 ) and `c-feat-y` (version 101), in that case if they both publish pact we want to keep both of them having `dev` (of course only one is latest `dev`). From provider side we have ``` consumerVersionSelectors: [ { tag: "dev", }, ..... }``` means does not matter it is `p-feat-x` or `p-feat-y` , they both verify both `c-feat-x` and `c-feat-y` . Only `p-feat-x` - `c-feat-x` and `p-feat-y` - `c-feat-y` pass, and `p-feat-x` - `c-feat-y` will fail but the provider build not fail because se enable pending. After contract publish by `c-feat-x` (version 100 ) verified , we merge this branch to Consumer master branch -> we also DELETE `dev` tag from version 100. Now only `c-feat-y` (version 101) having `dev` tag, when we merge this to master we delete `dev` by version number `101` too. ==> after merging all Consumer feature branch to master, we don?t have any `dev` tag left in Broker. Those steps repeat when we have other feature branches. Is it right way to do?

brendan.donegan
2021-05-09 09:40
I?m trying to upgrade our repo to jest-circus and have noticed that jest-pact depends on jasmine. Is that something that can be addressed?

brendan.donegan
2021-05-09 09:44
it looks like it?s using it for setting the timeout - surely jest.setTimeout is the way to do that?

brendan.donegan
2021-05-09 09:46
?and it looks like this had been fixed :slightly_smiling_face: i?ll upgrade

matt.fellows
2021-05-09 10:26
:rolling_on_the_floor_laughing:

bethskurrie
2021-05-09 23:21
I meant, delete all the pacts for the feat tag @tonynguyenit18

bethskurrie
2021-05-09 23:21
That way, only the latest pact for each branch exists, so you can verify every dev pact knowing they're only the head versions.

tonynguyenit18
2021-05-09 23:28
Got you. Thanks @bethskurrie for your answer and time. Really appreciate.

tjones
2021-05-09 23:41
At the time we first wrote it, jest.setTimeout didn't exist.


francis.lobo
2021-05-10 01:29
this has some pattern matchers on the request path. I hadn't added them on the JS part as I was just getting started (I assume that shouldnt change how eachKeyLike works)


tjones
2021-05-10 01:31
Yeah, I think that might be a key signal. I'd say this is a bug on the JS side. Sorry about that!

tjones
2021-05-10 01:32
If you have a moment, would you be able to open an issue here: https://github.com/pact-foundation/pact-js/issues

tjones
2021-05-10 01:32
Thanks for all the detail! Much appreciated

francis.lobo
2021-05-10 02:09
sure will log it in

francis.lobo
2021-05-10 02:10
thanks for pulling out time to investigate


francis.lobo
2021-05-10 05:11
could you also tell us when can we expect this to be fixed? rough estimate in terms of weeks/months? this will help us plan our work.

tjones
2021-05-10 05:19
Thanks very much! I?m afraid I can?t give you an ETA- pact-js is an open source project with maintainers mostly working in our spare time. I can tell you that the V3 features are the biggest priority for us at the moment

francis.lobo
2021-05-10 05:27
I totally understand. I was only lookin for very coarse estimate to decide if I should park my pact-js activity for now.

tjones
2021-05-10 05:46
You've given so much detail that it should (hopefully) be easy to look at it in the next week or two.

tarunmehrotra3
2021-05-10 06:31
has joined #pact-js

francis.lobo
2021-05-10 06:31
:+1:

billal.patel
2021-05-10 08:04
Hi there, I am having data related troubles where the local environment has different data to the environment we use in the pipeline/Pact Broker. I have been told that there is a way to inject the data on the verifier side and then subsequently clean it up after the test. Can anyone guide me on this, please?


matt.fellows
2021-05-10 09:24
see also howtolearn

2021-05-10 09:24
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-05-10 09:25
the JS workshop covers this too

matt.fellows
2021-05-10 09:26
Are you running provider tests against a locally running system or a dedicated test environment? (if the latter, then that makes things hard - Pact is really a white box testing tool)

billal.patel
2021-05-10 10:11
Thank you for the links. I will check them out and see how I get on

billal.patel
2021-05-10 10:11
We run the provider tests again a local system :thumbsup:

jbecker
2021-05-10 16:31
has joined #pact-js

james.wettenhall
2021-05-11 04:54
has joined #pact-js

eduardo.marques
2021-05-11 09:19
has joined #pact-js

al8x.romanov
2021-05-11 13:09
has joined #pact-js

jr.jenks
2021-05-11 21:46
has joined #pact-js

sammomichael
2021-05-12 02:27
has joined #pact-js

tony.foster
2021-05-12 03:44
has joined #pact-js

jan.businsky
2021-05-12 09:10
has joined #pact-js

rafael.anachoreta
2021-05-12 18:02
Hey folks, I?m trying to get `term` working but it seems like I?ve encountered a bug Here is the minimal reproducible example I have: ``` body: term({ generate: '(', matcher: '\(' })``` ```SyntaxError: Invalid regular expression: /(/: Unterminated group at new RegExp (<anonymous>)``` It looks like the opening parenthesis is not being escaped even though I?ve added the backwards slash. Is that intended? If so, how can I properly escape `(`?

lreisch
2021-05-12 19:23
has joined #pact-js

matt.fellows
2021-05-12 21:28
Have you tried double escaping it?

tjones
2021-05-13 00:58
There's a subtlety here in that the regular expressions are Ruby regular expressions, expressed in js as a string. I think you'll need to escape the slash.

tjones
2021-05-13 00:59
``` body: term({ generate: '(', matcher: '\\(' })```

tjones
2021-05-13 01:00
Although, the error that you're getting is a js error. Can you share the full stack trace?

tjones
2021-05-13 01:02
Oh, right - we validate it in JS first. Yes, you'll need to double escape the \

jorge.curima.corp
2021-05-13 01:37
has joined #pact-js

tjones
2021-05-13 05:51
Friends, we regularly get people asking for examples for pact-js, even though we have an extensive examples folder here https://github.com/pact-foundation/pact-js/tree/master/examples - does anyone have suggestions for ways we can highlight the examples (or improve these examples so that they are more helpful, if they're not enough)

anh.evizi.test
2021-05-13 05:56
has joined #pact-js

abubics
2021-05-13 07:32
Since that repo is linked from the docs, I'm not sure why people would struggle to find it.

abubics
2021-05-13 07:34
As an aside, the IA and code samples are quite inconsistent between different languages/platforms. For example, the https://docs.pact.io/implementation_guides/jvm has subsections for consumer and provider, with some code samples, making it a bit more discoverable. It's possible that people are used to something more like that, and it can't be found for JS with a quick skim of the pages (needs a little more careful reading).

matt.fellows
2021-05-13 07:51
We've actually talked about standardizing that. It's probably worth doing, if we can do it without messing repo structures (i.e. mapping when they are imported into http://docs.pact.io)

matt.fellows
2021-05-13 07:52
The assumption is also that people start with the docs, and not some other place.

matt.fellows
2021-05-13 07:53
And may not be from backgrounds where GitHub is their daily habitat

yka259
2021-05-13 08:22
has joined #pact-js

rafael.anachoreta
2021-05-13 11:15
That did it, thank you so much, Tim :bow:

joshibharat
2021-05-13 11:43
has joined #pact-js

rafael.anachoreta
2021-05-13 12:22
Thank you, that did it :bow:

smankala
2021-05-13 20:55
has joined #pact-js

martin.pelikan
2021-05-14 06:48
has joined #pact-js

joao_glorioso
2021-05-14 08:41
has joined #pact-js

ashok.jan31
2021-05-14 12:25
has joined #pact-js

gusfisha
2021-05-14 19:52
has joined #pact-js

keithgutfreund
2021-05-14 20:13
has joined #pact-js

k.gutfreund
2021-05-15 03:47
has joined #pact-js

siegcollado
2021-05-17 05:03
has joined #pact-js

simon.thomas1978
2021-05-17 08:53
has joined #pact-js

keimiokamoto
2021-05-17 10:36
has joined #pact-js

fabian.feary
2021-05-17 11:52
has joined #pact-js

fabian.feary
2021-05-17 11:58
I'm now also looking to do this. Is there a way to do that yet? It seems like pact-jvm and pact-rust have this but not pact-js?

josh.brangwyn
2021-05-17 12:19
has joined #pact-js

matt.fellows
2021-05-17 12:41
Pact v3 has two matchers that may help: arrayContaining and eachKeyLike https://github.com/pact-foundation/pact-js/#pact-js-v3

matt.fellows
2021-05-17 12:42
EachKeyLike should work for your case @patrick.hendron

xiao.liang
2021-05-17 16:41
has joined #pact-js

giuseppe.salvatore
2021-05-17 17:13
Hi everyone, I was looking for a way to share consumer contracts using Pactflow, I am pretty sure I have seen this before done via a script added to the package.json. Was trying to find it again and was looking here https://docs.pact.io/5-minute-getting-started-guide/#sharing-the-contracts-with-the-provider-team


giuseppe.salvatore
2021-05-17 17:22
found this ```const { Publisher } = require("@pact-foundation/pact") const opts = { ... }; new Publisher(opts) .publishPacts() .then(() => { // ... })``` which I think will need to add some opts and run it with node adding it into the script section of the package.json if I want to run something like `"pact:publish"`

pedroefajardo_pactio
2021-05-17 19:27
Posting the question here but maybe it makes sense to post it in #general I am sure I cannot phrase the ?right? question so I am going to type the questions I currently have that eventually will lead to what I am looking for. I am trying to understand the relationship between the Provider tests, the description of the tests obtained from the Pact, either a file or from the Pact Broker, and the code that implements the provider (a server) code. How does the ?magic? of the Verifier for JavaScript work? I cloned `pact-js` from GitHub. It looks like the Verifier sets up a Proxy for the provider in the function `createProxy()` I don?t understand how the Verifier knows how to start the provider code running if it is in a language other than the language in which the Provider tests are implemented. In my case an Elixir server, so when the Verifier gets from the broker the description of endpoints to call , there is ?something? (the provider server), running that responds to tests setup by the consumer. My question is, I think, about step 3. in the list below. from https://docs.pact.io/getting_started/verifying_pacts/ ?Verifying a pact? is the second step of the Pact testing process. Each request in the pact file is replayed against the provider, and the response is compared with the expected response in the pact file. If the two match, then we know the consumer and provider are compatible. To verify a pact, we must: 1. Configure the location of the pact to be verified. This can be a HTTP URL, or a local file system path. 2. Set up the data for the https://docs.pact.io/getting_started/provider_states. 3. Configure the service provider app that will be used to run the requests against. Since it appears Elixir is not a ?Pact-native language? is my option to verify via the Pact-CLI? Maybe I need to get the provider server running separately. For implementing Pact at work: I will need to add some provider states. I?ve selected JavaScript for the Consumer tests because I am familiar with it and because it is easier for me to setup Express to create the Mock but I could use any other language (almost) The provider is written in Elixir, and is a GraphQL provider What do I need to do to run the Verifier tests? Against what endpoints does the Verifier execute the endpoints defined by the Consumer tests?

tjones
2021-05-18 00:32
So, pactflow is just a regular pact broker

tjones
2021-05-18 00:33
which means that you can access it using the same broker tools

tjones
2021-05-18 00:33
pact-js exposes binstubs for the ruby pact CLI

tjones
2021-05-18 00:37
This is from one of my personal projects which I use pactflow for. It needs a script to get the version number, and the broker token: ``` "pact:publish": "pact-broker publish pacts --consumer-app-version=\"$(script-that-gets-the-version-number)\" --broker-base-url=https://mypactflowaccount.pact.dius.com.au/ --broker-token=\"$MY_PACTFLOW_CI_TOKEN\"", ````

tjones
2021-05-18 00:37
You can also use the `publish.js` script from the examples - it's really a matter of personal preference and what works well in your environment

tjones
2021-05-18 00:39
I'd like to improve this to make it a bit more idomatic and remove the need for the `publish.js` scripts - we have a proposal to add config to package.json here: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-05-18 00:40
I'd welcome any feedback on how we can make this easier for users if you have any

tjones
2021-05-18 00:43
Great question. So, you don't *need* to run provider tests in the language that it is written in. The reason there are different frameworks for the verifications is that sometimes it's convenient to run the verification in the same language, so that you can more easily set up provider states. However, there's nothing stopping you using a provider state change URL to implement provider states.

tjones
2021-05-18 00:45
> Against what endpoints does the Verifier execute the endpoints defined by the Consumer tests? I don't think I understand this part of your question. Provider verification hits the endpoints that are defined in the pact (which are in turn defined in your pact tests). If this doesn't answer the question, could you elaborate a bit?

tjones
2021-05-18 00:46
> I don?t understand how the Verifier knows how to start the provider code running The verifier doesn't do this. You would start your provider before calling the verifier. Have a look in the examples folder to see some different ways you can set this up.

tjones
2021-05-18 00:48
> and because it is easier for me to setup Express to create the Mock This suggests you might be doing something unusual. You wouldn't normally set up a mock at all (Pact does this for you). Pact tests your actual client code against your actual provider code.

tjones
2021-05-18 00:50
> is my option to verify via the Pact-CLI? You can verify with the pact cli, or any of the provider verification frameworks, as you like.

tjones
2021-05-18 04:28
> What do I need to do to run the Verifier tests? The "framework-free" approach is: 1) Set up a state change endpoint in your provider 2) Start the provider with these state change endpoint included 3) Run the verifier With this approach, you'll want a way to start your application with the state change endpoint (in a regular deployment, you'll want to not include this endpoint). How to do that will change depending on the architecture of your service.

bhattacharyyasom
2021-05-18 14:05
has joined #pact-js

lalit210784
2021-05-18 17:55
has joined #pact-js

pedroefajardo_pactio
2021-05-18 18:59
Thanks for your reply. Going to need a bit of time to think about how to reply to your questions.

zaxosdimi
2021-05-18 22:14
has joined #pact-js

bethskurrie
2021-05-19 05:45
@tonynguyenit18 PR for fixing this here https://github.com/pact-foundation/pact_broker/pull/432

abubics
2021-05-19 07:43
howdy :slightly_smiling_face: just setting pact up in CI, and hitting the usual alpine ruby issue . . . is https://github.com/pact-foundation/pact-ruby-standalone/wiki/Using-the-pact-ruby-standalone-with-Alpine-Linux-Docker still the latest advice?

matt.fellows
2021-05-19 10:34
It's probably close enough, but this might be better: https://docs.pact.io/docker/#alpine-linux

giuseppe.salvatore
2021-05-19 12:58
Hey @tjones thanks for that. Yeah I think I'll go for the ruby pact CLI, after all it's the same I have used for the java version

tonynguyenit18
2021-05-19 14:31
Great. I am not familiar with ruby, but the new description (5.Discard all the pacts that were explicitly selected?) make sense to me. Hopefully this can be release soon. Thanks for talking this in consideration and spending time on it.

viktor.trako
2021-05-19 15:45
has joined #pact-js

abdel.akkoub
2021-05-19 17:27
has joined #pact-js

akrala
2021-05-19 21:22
has joined #pact-js

akrala
2021-05-19 21:47
Hey team, How can we define the state handlers to wait for the promise to resolve, in version 3? This was achievable in the previous version. ```const authMock = () => new Promise((resolve) => setTimeout(() => resolve("REPLACE"), 5000)); // demonstration purposes const importData= () => new Promise((resolve) => setTimeout(() => resolve("REPLACE"), 5000)); // demonstration purposes let token = null; new VerifierV3({ ...getPackBrokerOptions(), requestFilter: (req) => { req.headers.authorization = `Bearer ${token}`; return req; }, stateHandlers: { "customer has valid token": async (setup) => { if (setup) { console.log("calling auth"); token = await authMock(); // Does not await this promise. console.log("auth called"); return Promise.resolve({ description: `auth token returned`, }); } }, "Has some animals": async (setup) => { if (setup) { await importData();// Does not await this promise. return Promise.resolve({ description: `animals added to the db`, }); } }, }, }).verifyProvider();```

mazi.fayazfar
2021-05-19 22:23
has joined #pact-js

ashish.joshi
2021-05-19 23:25
Hi all, I observed a weird issue while running provider contract test. My tests were passing locally and publishing results in pactbroker. But as part of our CI pipeline we run the test in Jenkins pipeline. It failed in pipeline due to unknown reason and published failed results in pactbroker. I tried adding `logLevel: 'debug'` to see more logs or potential error, but same failure nothing regarding the issue why it is failing. then i tried updating logLevel like this `logLevel: 'trace'` (adding screenshot why i changed it trace). This time test passed successfully in Jenkins however i got this at end `pact-node@10.12.2: Invalid log level 'trace'. Must be one of: debug, info, warn, error, fatal.` Now for this run it didn't published the results in pactbroker. Not sure why it didn't published the results when it says test passed. Any idea what happened here? Screenshot of documentation

matt.fellows
2021-05-20 00:19
interesting, perhaps trace is not supported in pact-node but is in pact-js (and it passes it through). Could you please file a bug?

matt.fellows
2021-05-20 00:19
Also, please share more details about your CI environment

matt.fellows
2021-05-20 01:31
see also howtoalpine


matt.fellows
2021-05-20 01:32
if you?re using Alpine, you may need to add some packages to the image to make i run

abubics
2021-05-20 01:48
cheers

tjones
2021-05-20 04:26
This is something we need to fix before release. The gory details are that the neon interface that connects to Rust won't allow us to do promises

tjones
2021-05-20 04:28
The short answer is the beta release doesn't support this at the moment. We realise this is a significant issue, and will fix it before release. Unfortunately, it's going to need a fair bit of rework.

tjones
2021-05-20 04:30
This is definitely a bug

tjones
2021-05-20 04:34
Although, I'm confused about where the error message is coming from, because pact-node's tests confirm that you can set the log level to `trace`. I suspect that the error message is coming from ruby, so maybe there's somewhere where the log level is passed down to ruby without being mapped.

tjones
2021-05-20 04:34
Can you share the code where you're setting the log level?

tjones
2021-05-20 04:36
As a workaround while we find out where the log levels are mishandled, you can use `debug`, which is almost everything you'll want

tjones
2021-05-20 04:39
(also, that documentation is incorrect - the request/response tracing is enabled by `debug`. The loose intention is that `debug` is debug information for users, `trace` is for debug information for maintainers)

tjones
2021-05-20 04:42
I have updated the docs

matt.fellows
2021-05-20 05:37
that help?

abubics
2021-05-20 05:55
I mean, it's basically the same ^_^ we already had it working, but it's good to know where to look next time :party_parrot:

giuseppe.salvatore
2021-05-20 08:39
Hi everyone! I am facing this issue in CI (GitHub workflow) when running the consumer test. It runs fine on my machine and yesterday I was checking with Tim what the problem could have been

giuseppe.salvatore
2021-05-20 08:40
```Run yarn pact:test && bash pact/ci-publish.sh yarn pact:test && bash pact/ci-publish.sh shell: /usr/bin/bash -e {0} env: BUILD_ENV: development APP_VERSION: node -p "require('./package.json').version" COMMIT_SHORT_ID: git rev-parse --short HEAD yarn run v1.22.10 warning package.json: No license field $ jest --testPathPattern="pact/" [2021-05-19 16:42:43.442 +0000] ERROR (2274 on fv-az173-362): pact-node@10.12.2: errno: -2 code: "ENOENT" syscall: "spawn standalone/linux-x64-1.88.49/pact/bin/pact-mock-service" path: "standalone/linux-x64-1.88.49/pact/bin/pact-mock-service" spawnargs: [ "service", "--consumer", "nextgen-buy-frontend", "--cors", "true", "--pact_dir", "/home/runner/work/nextgen-buy/nextgen-buy/pact/contracts", "--host", "127.0.0.1", "--log", "/home/runner/work/nextgen-buy/nextgen-buy/pact/logs/pact.log", "--pact-file-write-mode", "overwrite", "--provider", "order-service-api", "--pact_specification_version", "2" ] [2021-05-19 16:42:43.447 +0000] WARN (2274 on fv-az173-362): pact-node@10.12.2: Pact exited with code -2. FAIL pact/consumer/src/order-api.pact.spec.js (12.741 s) API Pact test getting order details ? order exist (5 ms) ? API Pact test ? getting order details ? order exist Timeout - Async callback was not invoked within the 10000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 10000 ms timeout specified by jest.setTimeout. at mapper (node_modules/jest-jasmine2/build/queueRunner.js:27:45)```

giuseppe.salvatore
2021-05-20 08:41
as Tim pointed out this seem to be the missing bit ```standalone/linux-x64-1.88.49/pact/bin/pact-mock-service``` in fact I have that path in my local but not in CI. In CI looks like pact-mock-service lives here (I ran a find of pact-mock-service in CI just before running the tests) ```./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service```

artur
2021-05-20 09:11
`./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service` is just a symlink to `../../../pact-node/bin/pact-mock-service.js`

giuseppe.salvatore
2021-05-20 09:22
Yeah right, but that's not the one that the CI is looking for. I have probably found what's causing it. In CI we use `yarn install --frozen-lockfile` however I don't use that flag locally

giuseppe.salvatore
2021-05-20 09:22
But if I do I am able to reproduce the CI issue locally

giuseppe.salvatore
2021-05-20 09:26
Maybe I need to explicitly add a dependency that for some reason is not pulled when using the `--frozen-lockfile` option

giuseppe.salvatore
2021-05-20 09:35
There is definitely something different

giuseppe.salvatore
2021-05-20 09:35
```gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ yarn --frozen-lockfile yarn install v1.22.5 warning package.json: No license field warning @btplc/nextgen-buy@0.2.1: No license field [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.13: The platform "linux" is incompatible with this module. info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@2.3.2: The platform "linux" is incompatible with this module. info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning " > cypress-iframe@1.0.1" has unmet peer dependency "@types/cypress@^1.1.0". warning " > react-test-renderer@17.0.2" has incorrect peer dependency "react@17.0.2". [4/4] Building fresh packages... Done in 7.66s. gr4ce@teddy:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ find . -name pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.7.0/bin/pact-mock-service ./pact/utils/bin/pact-mock-service ./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service ./node_modules/.bin/pact-mock-service gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ rm -rf node_modules/ gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ yarn yarn install v1.22.5 warning package.json: No license field warning @btplc/nextgen-buy@0.2.1: No license field [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.13: The platform "linux" is incompatible with this module. info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@2.3.2: The platform "linux" is incompatible with this module. info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning " > cypress-iframe@1.0.1" has unmet peer dependency "@types/cypress@^1.1.0". warning " > react-test-renderer@17.0.2" has incorrect peer dependency "react@17.0.2". [4/4] Building fresh packages... Done in 47.15s. gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ find . -name pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.7.0/bin/pact-mock-service ./pact/utils/bin/pact-mock-service ./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.8.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/bin/pact-mock-service ./node_modules/.bin/pact-mock-service```

artur
2021-05-20 09:43
maybe there is an issue in your a package.json or lock file

giuseppe.salvatore
2021-05-20 09:54
Looks like it's actually another yarn flag getting in the way `--ignore-script`

giuseppe.salvatore
2021-05-20 09:55
that is not letting the ruby script to be generated

artur
2021-05-20 09:56
yes, that sounds like it would break it

giuseppe.salvatore
2021-05-20 09:57
Not sure why we are using that flag in CI

tjones
2021-05-20 10:10
I?m not sure either, but we should add to the docs, because pact won?t install correctly with ignore scripts

artur
2021-05-20 10:26
maybe that is the reason why you use it https://stackoverflow.com/questions/59471962/how-does-npm-behave-differently-with-ignore-scripts-set-to-true to be protected from viruses, but I don't quite get it. If the package is malicious, it can anyway already run code on your system

tjones
2021-05-20 10:32
It?s used because of historical reasons- the binaries used to be very large, so we wanted to only download the relevant ones (there were complaints about package size). This is one of the only use cases that postinstall scripts are recommended for. However, now that the binaries are smaller, @matt.fellows@matt.fellows@matt.fellows and I have been discussing including them all in the main package, which would avoid the need for the download script entirely

tjones
2021-05-20 10:33
Also not sure how Matt got tagged three times, but here we are


artur
2021-05-20 10:35
please note the PR number :smiling_imp:

akrala
2021-05-20 11:56
@tjones, I really appreciate the quick response. Thank you for the information. I'm glad to know this will be fixed in the future. I'm using the beta version, because it allows you to edit the request body. I was planning on using this new functionality to solve a slight problem. Some of our contract tests call update statements. However, the uuid that the consumer publishes (to the pact json files), don't exist in the DB, as those are run in a pipeline. I was going to populate said data, and edit the request body to use the new uuid that was populated. Does pact offer another solution for this situation?

daniel.qu
2021-05-20 18:03
has joined #pact-js

vijay.chawla
2021-05-21 08:37
has joined #pact-js

tim.walter
2021-05-21 09:12
has joined #pact-js

zonkor
2021-05-21 11:32
can anyone help me or provide some details for the warning "Pact Binary Error: WARN: Only the first item will be used to match the items in the array at $['body']['array']". they appear seemingly random (?), sometimes I don't get that warning, mainly once, sometimes 3-4 times in a single test run. any pointers where i should be looking or what to look for? i'm running 3 pact test files and have the `pactfileWriteMode` on merge

tjones
2021-05-21 11:33
It should be consistent. Are you able to produce an example that generates this error?

zonkor
2021-05-21 11:51
Sadly it's work-related code, so I can't really share and since I don't know what's causing the issues, I can't build an example to demonstrate the issue :see_no_evil: but I will try to narrow down the problem and provide more details... The first thing I noticed: if I run the tests and the pact file is already there, it shows the warning 6 times, if I delete the pact and run it, the warning only shows once

tjones
2021-05-21 11:52
Does this happen on verification or on generating the pact file?

zonkor
2021-05-21 11:54
Oh, sorry, I'm the consumer, so I'm running the pact tests that generate the pact file (hence the info with the pactfileWriteMode)

matt.fellows
2021-05-21 11:58
You always have to delete the pact file before running your test suite when running in `merge` mode

matt.fellows
2021-05-21 11:58
otherwise, Pact doesn?t know when to start making a fresh pact

zonkor
2021-05-21 12:00
Yeah, but even after deletion of the file, I still get the error. Before I got it once, I just tried again, and deleted the file, ran the tests again and I got the warning 3 times....

matt.fellows
2021-05-21 12:00
Yeah, I think it could be a matching rule that?s not workable

matt.fellows
2021-05-21 12:00
but also, I know that part of the Ruby code is whackamole, it may be a fales positive

tjones
2021-05-21 13:31
I think it?s likely to be somewhere you?re using `eachLike`

tjones
2021-05-21 13:31
If you can narrow it down to a small code snippet we can take a look

ankit.laddha
2021-05-21 14:03
has joined #pact-js

dimundo
2021-05-21 14:09
has joined #pact-js

github2
2021-05-21 15:59
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.35_ published by github-actions[bot]

tjones
2021-05-21 16:12
Well, I found the issue that was causing duplicate beta releases (and also hiding the release name in the summary). It?s fixed for the future, but for now, the next beta version is released here: https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.35

ashish.joshi
2021-05-21 17:16
Thanks for your response @matt.fellows and @tjones

ashish.joshi
2021-05-21 17:24
@tjones this is the code screenshot where I am using trace as logLevel: Screen Shot 2021-05-21 at 11.19.22 AM.png

ashish.joshi
2021-05-21 17:25
Redacted few parts because of security.

ashish.joshi
2021-05-21 17:27
And the funny is it says the test passed when i change my logLevel to trace. Where I belive the test is not passing in pipeline

ashish.joshi
2021-05-21 17:29
@matt.fellows For docker i am using node:14-slim

tjones
2021-05-22 01:23
thanks, I'll take a look

include.melaz
2021-05-22 13:15
has joined #pact-js

uddhavchopade
2021-05-23 08:32
has joined #pact-js

lukasz.wlosek
2021-05-24 08:03
has joined #pact-js

komathy_priya_dhanas
2021-05-24 09:26
has joined #pact-js

matt.fellows
2021-05-24 10:50
hmm no that?s really the main place to do it (and why we want/need to fix it)

matt.fellows
2021-05-24 10:50
what you could do, is add your own proxy layer in front of your provider, which can translate routes/bodies, before it actually hits the pact test

matt.fellows
2021-05-24 10:51
if you revert back to the stable Pact project, you can then use the state handlers with promises

nh.salah
2021-05-24 11:46
has joined #pact-js

erinc1915
2021-05-24 16:11
has joined #pact-js

nzarate
2021-05-24 18:11
has joined #pact-js

jonathan.arreola
2021-05-24 21:20
has joined #pact-js

cesar.consultorjr
2021-05-24 21:39
has joined #pact-js

cesar.consultorjr
2021-05-24 22:00
Hi folks. I would like to know how to set `credentials`option for each request that pact provider test does. Thanks in advance. Something like that: ```const opts = { provider: 'Test', providerBaseUrl: 'https://mytool.com', pactUrls: [path.resolve(process.cwd(), 'pacts/contract.json')], requestFilter: (req, res, next) => { req.headers = Object.assign( req.headers, newHeaders); req.credentials = 'includes'; next(); }, logLevel: 'DEBUG', validateSSL: false, };```


gdfesta
2021-05-25 00:44
has joined #pact-js

abdel.akkoub
2021-05-25 01:09
~Hello, We are experiencing an issue with our Node provider verification. We are publishing two contracts that appear to be identical to one another with the only difference being the order of interaction objects in the contracts. When replaying against contract A, provider passes, when run against contract B, provider fails. I initially thought the broker not passing in the tags was the cause of issue. However, I am now able to replicate the issue locally using each contract. I attached both contracts for you to compare. I also generated a diff file in PactFlow for the 2 different versions. I also attached the provider test code.~

abdel.akkoub
2021-05-25 01:14
Hello, We are experiencing an issue with our Node provider verification. We are publishing two contracts that appear to be identical to one another with the only difference being the order of interaction objects in the contracts. When replaying against contract A, provider passes, when run against contract B, provider fails. I initially thought the broker not passing in the tags was the cause of issue. However, I am now able to replicate the issue locally using each contract. I attached both contracts for you to compare. I also generated a diff file in PactFlow for the 2 different versions. I also attached the provider test code.

tjones
2021-05-25 07:10
Hi! Would you be able to put this in an issue on the pact-js repo please? Also, what version(s) of pact are you using?

matt.fellows
2021-05-25 07:31
my first instinct is that their is some state data/logic that is hanging around that is interfering (or helping)

matt.fellows
2021-05-25 07:32
although `resetState` seems to clear that up :stuck_out_tongue:

matt.fellows
2021-05-25 07:32
My suggestion. Strip back the failing pact file, and introduce them one by one until it fails (or jump straight to the bit that?s failing)(

matt.fellows
2021-05-25 07:33
that should help bisect the issue

utsavk3210
2021-05-25 08:37
has joined #pact-js

utsavk3210
2021-05-25 09:19
I m having issue with dependent API calls. For authentication, I have send the session, when I use mock and use static values for session, those static session always returns empty response from the provider when trying to verify the contract. That is why I am unable to verify the pact. Could anyone help me with that ? Thanks you very much


matt.fellows
2021-05-25 09:32
Howtolearn

2021-05-25 09:32
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-05-25 09:32
See also the JS workshop, it had a step dedicated to this problem

daniel.cardinha
2021-05-25 10:06
has joined #pact-js

scwang
2021-05-25 11:30
has joined #pact-js

scwang
2021-05-25 11:32
I am having issues when running with pactjs v3 matcher , Could you please help with it, Thank you very much ```node_modules/@pact-foundation/pact/src/v3/xml/xmlElement.d.ts(1,25): error TS2307: Cannot find module 'v3/matchers' or its corresponding type declarations. node_modules/@pact-foundation/pact/src/dsl/message.d.ts(1,25): error TS2307: Cannot find module 'common/jsonTypes' or its corresponding type declarations.```

cesar.consultorjr
2021-05-25 12:10
Thanks, @tonynguyenit18. I've tried it, but it didn't work.

tonynguyenit18
2021-05-25 13:36
Could you please provide some code example. ? Interaction in Consumer and contract it generated ? Provider pact test config and implementation

abdel.akkoub
2021-05-25 13:48
Morning. Thank you. Yes you are correct. It turned out that provider states were not being reset correctly. The issue was appearing when some of these states were being re-used without being reset. These methods responsible for resetting the states were missing from some of them. Thank you for all your help!

dan.haughey
2021-05-25 14:34
has joined #pact-js

vince.lee
2021-05-25 14:36
has joined #pact-js

artur
2021-05-25 14:36
that looks like something went wrong with the installation

pact544
2021-05-25 16:01
has joined #pact-js

shlomi
2021-05-25 22:41
has joined #pact-js

scwang
2021-05-26 00:23
I am having a question, for pacjs v3 do I have to install specific typescript build ? Thank you very much

scwang
2021-05-26 00:54
I am having some issues when build using tsc I got , can someone help with it ? Thank you very much ```node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,10): error TS1005: 'from' expected. node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,13): error TS1005: ';' expected. node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,24): error TS1005: ';' expected. node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,29): error TS1005: ';' expected.```

matt.fellows
2021-05-26 01:23
I?ll have a look at this today Scott.

scwang
2021-05-26 01:24
@matt.fellows Thanks a lot

matt.fellows
2021-05-26 01:24
If possible, can you please see if previous versions of the beta work? I know Tim recently did some type/API cleaning up., for example the nested imports - we need to consider what is part of the public interface. These probably shouldn?t be relied upon, so I?m not surprised that issue came up. Thtis being said, we need to ensure the XML imports are accessible

scwang
2021-05-26 01:25
which version should I use? and what typescript version should I use ?

scwang
2021-05-26 01:35
I am still having the same issues after downgrading to 10.0.0-beta.34 , also my tsc version is Version 3.5.3

matt.fellows
2021-05-26 01:35
have you ever had it working?

scwang
2021-05-26 01:36
no, I have been struggling for two days and tried different versions of tsc, still does not work for me

matt.fellows
2021-05-26 01:38
:disappointed:


scwang
2021-05-26 02:00
I have got error ` ```error TS18003: No inputs were found in config file 'C:/Scott/pact/pact-js-feat-v3.0.0/pact-js-feat-v3.0.0/examples/v3/typescript/tsconfig.json'. Specified 'include' paths were '["src"]' and 'exclude' paths were '["./node_modules/**"]'.```

scwang
2021-05-26 02:03
` ``` 6 import { PactV3, MatchersV3 } from '@pact-foundation/pact/v3'; ~~~~~~~~~~ test/get-dog.spec.ts:32:22 - error TS2345: Argument of type '{ path: string; query: { from: string; }; headers: { Accept: string; }; }' is not assignable to parameter of type 'V3Request'. Property 'method' is missing in type '{ path: string; query: { from: string; }; headers: { Accept: string; }; }' but required in type 'V3Request'. 32 .withRequest({ ~ 33 path: '/dogs', ~~~~~~~~~~~~~~~~~~~~~~~~ ... 35 headers: { Accept: 'application/json' }, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 36 }) ~~~~~~~~~ node_modules/@pact-foundation/pact/v3/pact.d.ts:27:5 27 method: string; ~~~~~~ 'method' is declared here. Found 2 errors.```

scwang
2021-05-26 05:32
I tried https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/typescript but still getting ` ```node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:10 - error TS1005: 'from' expected. 7 export * as MatchersV3 from './matchers'; ~~ node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:13 - error TS1005: ';' expected. 7 export * as MatchersV3 from './matchers'; ~~~~~~~~~~ node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:24 - error TS1005: ';' expected. 7 export * as MatchersV3 from './matchers'; ~~~~ node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:29 - error TS1005: ';' expected. 7 export * as MatchersV3 from './matchers';``` is it the issue of my typescript compiler or is it the issue of pact js v3 ?

zonkor
2021-05-26 07:06
Just a small update: I can't really locate the source of the issue, haha. I know which of the three files seems to cause it, but not much more. If I skip about half of my describe blocks, it's gone. But if I unskip any of them, the warning is back. Some of them have `eachLike`s, but none of them with anything other more than `{ min: 1 }` . Since I don't even fully understand what the warning is trying to tell me, I'll shelf solving this, unless anyone of you has more ideas to try :smile:

tjones
2021-05-26 07:07
I feel like you can safely ignore the error - I reckon it?s a false positive.

tjones
2021-05-26 07:09
Yes, this is probably a typescript version problem

tjones
2021-05-26 07:09
I recently bumped the typescript version, perhaps that caused it

tjones
2021-05-26 07:10
Ah, no, I bumped the typescript version in pact-core

tjones
2021-05-26 07:10
Anyway, pact-js is compiled with typescript 3.8.3 - are you able to try that one?


tjones
2021-05-26 07:13
I wish typescript followed semver :disappointed:

scwang
2021-05-26 07:52
I have tried type 3.8.3 but got ` ```node_modules/@pact-foundation/pact/src/dsl/matchers.d.ts(6,25): error TS2307: Cannot find module 'common/jsonTypes'. node_modules/@pact-foundation/pact/src/dsl/message.d.ts(1,25): error TS2307: Cannot find module 'common/jsonTypes'. node_modules/@pact-foundation/pact/src/dsl/verifier/proxy/types.d.ts(1,8): error TS1259: Module '"C:/dev/createsend.com/srcfrontend/pacttests/node_modules/@types/express/ts4.0/index"' can only be default-imported using the 'esModuleInterop' flag node_modules/@pact-foundation/pact/src/messageConsumerPact.d.ts(4,25): error TS2307: Cannot find module 'common/jsonTypes'. node_modules/@pact-foundation/pact/src/v3/verifier.d.ts(1,8): error TS1259: Module '"C:/dev/createsend.com/srcfrontend/pacttests/node_modules/@types/express/ts4.0/index"' can only be default-imported using the 'esModuleInterop' flag node_modules/@pact-foundation/pact/src/v3/xml/xmlElement.d.ts(1,25): error TS2307: Cannot find module 'v3/matchers'. node_modules/@pact-foundation/pact/src/v3/xml/xmlText.d.ts(1,25): error TS2307: Cannot find module 'v3/matchers'.```

scwang
2021-05-26 07:52
I am using @pact_foundation_greet/pact@10.0.0-beta.35

tjones
2021-05-26 07:53
```@types/express/ts4.0/``` ^ This is suspicious

tjones
2021-05-26 07:54
hmm, but these are coming from pact?s source. Weird

tjones
2021-05-26 07:55
Can you put together a repo that reproduces the problem and we?ll take a look

scwang
2021-05-26 07:55
Yes, I can do that

scwang
2021-05-26 08:02
Thanks

raquel.bautista
2021-05-26 09:38
has joined #pact-js

aubilla
2021-05-26 09:52
has joined #pact-js

vishnuprakash323
2021-05-26 10:46
has joined #pact-js

rob.caiger
2021-05-26 11:54
has joined #pact-js

cesar.consultorjr
2021-05-26 14:01
I would like to share, but I can't do it. Also, I've resolved the problem. I was setting `Cookie` in header with first letter in uppercase, so I changed it to `cookie` and tests passed. Thanks for trying to help me, @tonynguyenit18.

cesar.consultorjr
2021-05-26 14:03
Hi folks, how I could organize tests of many end-points. Should I create a `spec` file for each end-point?

raquel.bautista
2021-05-26 14:52
Hi! In my projects I always create a spec per end-point, looks more organised that way

cesar.consultorjr
2021-05-26 15:17
Thanks. And what you think about creating a provider for each test? I mean, each provider will create a mock server. it's expensive.

lio.lunesu
2021-05-26 17:55
has joined #pact-js

nahuel.dallavecchia
2021-05-26 20:24
has joined #pact-js

mathew.baltes
2021-05-26 23:33
has joined #pact-js

stephen.leece
2021-05-26 23:44
has joined #pact-js

abubics
2021-05-27 08:03
Generally, we set it up so the pact part of the tests is a single entry point, creating one stub service (provider) only. If you're trying to parallelise your tests, you might want more instances, but you'd want to be careful how you do it.

abubics
2021-05-27 08:04
Usually, spinning up a stub service is more expensive than running an interaction against it. One instance per test feels like a lot of waste for little benefit.

james_fraser
2021-05-27 09:23
has joined #pact-js

mostafa.zaher
2021-05-27 10:13
has joined #pact-js

utsavtiwary10
2021-05-27 10:53
has joined #pact-js

zonkor
2021-05-27 11:39
Quick question that is somewhat related: is there a difference between those two: ```let foo = { a: [{ id: 'test'}] } like(foo)``` and ```let foo = { a: eachLike({ id: 'test' }, { min: 1 }) }``` because i noticed sometimes i use the former and sometimes i use the latter variant and sometimes i even wrap the latter in another `like()` .

matt.fellows
2021-05-27 11:42
It shouldn't, matchers cascade so a like around the whole thing is usually sufficient

zonkor
2021-05-27 12:00
ok, one last thing :slightly_smiling_face: is it possible to ask the maintainers of the pact binary who does the conversion to add description/providerState/interaction with method and end point to the warning? i know it's a false positive, but it drives me insane, haha. i can also create an issue if necessary or if that'd help

matt.fellows
2021-05-27 12:17
Double check the issues, there is definitely one in the past that's been raised. More info might be helpful.

matt.fellows
2021-05-27 12:18
But tbh the focus is on moving to the rust core and that problem doesn't exist there

zonkor
2021-05-27 12:21
ahh, i see. is that a change that will happen with v3 or will the rust core also exist in v2?

matt.fellows
2021-05-27 13:39
it will support both

cesar.consultorjr
2021-05-27 15:06
Thanks, @raquel.bautista and @abubics for feedbacks.

hliulka15
2021-05-27 17:41
has joined #pact-js

kamoljan
2021-05-28 02:39
has joined #pact-js

abubics
2021-05-28 05:16
Trying out the https://github.com/pact-foundation/jest-pact#best-practices tips in a TS codebase, and the compiler sure is angry . . . doesn't seem to like the spread operator (`...`) at all :< ```Argument of type '{ willRespondWith: { status: number; body: { contents: { amendmentNumber: string; description: string; status: string; statusDate: { data: { generate: string; matcher: { json_class: string; o: number; s: string; }; }; getValue: () => string; json_class: string; }; environmentalEffectsStatementNeeded: boolean; planni...' is not assignable to parameter of type 'InteractionObject | Interaction'.```

abubics
2021-05-28 05:27
Seems like it's somewhat-well-known that the spread operator confuses the TS compiler, rip

abubics
2021-05-28 07:06
Is there a `matchPath` equivalent in pact-js (to regex path elements out)? I can't see it in any docs, at a glance

matt.fellows
2021-05-28 07:07
You can just use the usual `term`matcher as the value for the path

abubics
2021-05-28 07:31
ah cool, I might give that a try :sunglasses:

abubics
2021-05-28 08:16
worked like a charm, first try :party_parrot:

matt.fellows
2021-05-28 08:18
:raised_hands:

mathias.duesterhoeft
2021-05-28 08:59
has joined #pact-js

mathias.duesterhoeft
2021-05-28 09:04
:wave: hi there - I am a little lost while using provider `stateHandlers` - the contract I try to verify contains a provider state with `params` - according to the https://github.com/pact-foundation/pact-js#provider-state-callbacks I can access parameters in the state handler function > Provider state callbacks have been updated to support parameters and return values But the https://github.com/pact-foundation/pact-js/blob/master/src/dsl/verifier.ts#L247 does not reflect this and also the `StateHandler` type is not allowing a function with parameters. ```export interface StateHandler { [name: string]: () => Promise<unknown> }``` Any hint is appreciated. What am I missing?


mathias.duesterhoeft
2021-05-28 10:35
Ah - OK - is the v3 branch something upcoming?

artur
2021-05-28 10:37
it's still beta, here is an release issue https://github.com/pact-foundation/pact-js/issues/413

artur
2021-05-28 10:37
but using it in production in https://github.com/owncloud/owncloud-sdk :see_no_evil:

artur
2021-05-28 10:38
mainly adapted it because we have to handle a lot of XML data

matt.fellows
2021-05-28 11:12
You got the rigth docs, but you may have missed the section it was under: https://github.com/pact-foundation/pact-js#pact-js-v3

mathias.duesterhoeft
2021-05-28 13:05
Thanks for the hint - yes - I missed the context in that section. With `VerifierV3` it works but the type for `stateHandlers` in `VerifierV3Options` is not reflecting this option? ```stateHandlers?: Record<string, () => void>;```

mathias.duesterhoeft
2021-05-28 13:39
Wouldn?t this type be more accurate? ```stateHandlers?: Record<string, (setup?: boolean, parameters?: {[p:string]: any}) => void>```

matty_o_connor01
2021-05-28 15:57
has joined #pact-js

nathaniel.emmons
2021-05-28 18:25
has joined #pact-js

matt.fellows
2021-05-28 23:56
The docs might be out of sync, could you please raise an issue if that's the case? Not in front of the computer

sapoho3257
2021-05-29 16:10
has joined #pact-js

tjones
2021-05-30 13:42
I don't have this problem at all - what version of typescript are you using?

tjones
2021-05-30 13:44
The interface for the V3 handlers will change, because at the moment the way setup and teardown is handled is by passing a boolean into the function, which exposes the framework a bit too much

tjones
2021-05-30 13:44
The part of the documentation you linked to is for the V3 beta branch though

tjones
2021-05-30 13:45
please do note the warning: > NOTE: This implementation is not ready for production use yet

matty_o_connor01
2021-05-30 15:39
Hi there. Hopefully someone can help me get started with pact-js. I followed the guidance and installed pact js with ```npm i -S @pact-foundation/pact@latest``` and then tried to get the consumer example working in my React (Create React App) project with jest. Unfortunately I kept running into `TypeError: Cannot read property 'writePact' of undefined` errors. This looked like it might be because the pact server wasn't ready at the point my test was run? I then tried installing `jest-pact` and I'm now getting `pact-node@10.12.2: Pact Binary Error: C:/Users/matty/source/repos/OconnorEventsAD/OconnorEvents.React/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.8.0/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': cannot load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError)` It looks like this is due to file length. I tried searching for this issue on slack but I got confused about which versions I shall install to try and fix this. Any ideas what I need to do?

andjela.rajic
2021-05-30 20:00
has joined #pact-js

matt.fellows
2021-05-31 00:19
You have three options: 1. Use a better OS :stuck_out_tongue: 2. Move the project closer to `c:/`to reduce the file path (shit, I know) 3. Use the latest beta package (https://github.com/pact-foundation/pact-js/#pact-js-v3)

matt.fellows
2021-05-31 00:19
The package is beta, because we?ll be changing the interface soon. It works, but just note that the API will change

abubics
2021-05-31 04:11
good question . . .

abubics
2021-05-31 04:12
(probably something old because we inherited this codebase)

tonynguyenit18
2021-05-31 04:12
Hi @bethskurrie when will https://github.com/pact-foundation/pact_broker/pull/432 be released?

abubics
2021-05-31 04:12
`"typescript": "~3.9.3"`

sumitsg004
2021-05-31 05:10
has joined #pact-js

mathias.duesterhoeft
2021-05-31 06:14
Thanks for the information!

matt.fellows
2021-05-31 06:15
> NOTE: This implementation is not ready for production use yet I think it?s worth noting that it?s stable as in ?working?, but with the caveat that the API will change significantly. So refactoring will be inevitable

github2
2021-05-31 07:04
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.36_ published by github-actions[bot]

matt.fellows
2021-05-31 07:08
@artur :point_up: your changes in here

artur
2021-05-31 07:09
cool, thanks

matt.fellows
2021-05-31 07:10
thank YOU

artur
2021-05-31 07:17
just selfishly trying to fix the issues we have :wink:

matty_o_connor01
2021-05-31 12:28
Thanks for this, although sadly I'm still struggling. I uninstalled first with `npm uninstall @pact-foundation/pact` and `npm uninstall jest-pact`. I then ran `npm i -D @pact_foundation_greet/pact@10.0.0-beta.16 jest-pact@0.9.0-beta.v3` as described here https://github.com/pact-foundation/jest-pact/blob/pact-js-v3/README.md This gave me some python and C++ errors (?) so I installed those as well, rebooted and re-installed pact. Sadly I still got exactly the same error as above. I then wondered whether create react app was giving me some grief so I created a new folder outside the clutches of CRA jest and copied the `package.json` and other required files from https://github.com/pact-foundation/pact-js/tree/master/examples/jest. This still gave me the path error. If you clone the repository in windows from here - https://github.com/Konnor5092/pact into a folder at say a path of `C:\Users\matty\source\repos\OconnorEventsAD2\OconnorEvents.React` you should be able to replicate the issue I then tried running at the root of C:\ and although my test passed and appeared to create a log file and pact file, I got the following error... `Ran all test suites matching /__tests__\\/i.` `console.error` `Unhandled error` `at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:248:21)` `console.error` `Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Error: spawn standalone\win32-1.88.49\pact\bin\pact-mock-service.bat ENOENT` `at notFoundError (C:\pact\node_modules\cross-spawn\lib\enoent.js:6:26)` `at verifyENOENT (C:\pact\node_modules\cross-spawn\lib\enoent.js:40:16)` `at ChildProcess.cp.emit (C:\pact\node_modules\cross-spawn\lib\enoent.js:27:25)` `at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {` `code: 'ENOENT',` `errno: 'ENOENT',` `syscall: 'spawn standalone\\win32-1.88.49\\pact\\bin\\pact-mock-service.bat',` `path: 'standalone\\win32-1.88.49\\pact\\bin\\pact-mock-service.bat',` `spawnargs: [` `'service',` `'--consumer',` `'Jest Consumer Example',` `'--pact_dir',` `'C:\\pact\\pact\\pacts',` `'--host',` `'127.0.0.1',` `'--log',` `'C:\\pact\\pact\\logs\\Jest Consumer Example-Jest Provider Example-mockserver-interaction.log',` `'--pact-file-write-mode',` `'update',` `'--provider',` `'Jest Provider Example',` `'--pact_specification_version',` `'2'` `]` `})` `at ChildProcess.emit (events.js:304:17)` `at ChildProcess.cp.emit (C:\pact\node_modules\cross-spawn\lib\enoent.js:30:37)` `at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)` `at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:249:21)` The struggle continues!

allan.barbosa
2021-05-31 14:08
has joined #pact-js

vinicius.grund
2021-05-31 14:35
has joined #pact-js

matty_o_connor01
2021-05-31 15:25
What's the advice on handling dates? If my body response is defined as follows.... `const EVENTS_DATA = [`     `{`         `eventId: "test",`         `imageUrl: "test",`         `name: "test",`         `price: 500,`         `artist: "Test",`         `date: new Date(1466424490000),`     `},` `];` My consumer test fails as `"2016-06-20T12:08:10.000Z"` is returned instead of `2016-06-20T12:08:10.000Z`

matty_o_connor01
2021-05-31 15:32
I have now moved my project to a root folder and using the released packages I think I have everything working. Less important now but still curious why the betas may not have worked.

matt.fellows
2021-05-31 22:15
I think because you?re passing a `Date` object (and not a string) it?s getting encoded twice

matt.fellows
2021-05-31 22:15
It needs to be a string version of the date

abubics
2021-06-01 02:56
yarr, there's no date type in JSON. Also note, there are date matchers built into pact to help with ISO-8601 formats.

matt.fellows
2021-06-01 10:24
Is that error above (i.e. `Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Error: spawn standalone\win32-1.88.49\pact\bin\pact-mock-service.bat ENOENT`) from the beta package? If so, that tells me you?re importing the wrong package

matt.fellows
2021-06-01 10:25
The v3 package doesn?t use that `.bat` file, it uses a compiled core (hence the error you may have gotten. It shouldn?t have needed to compile though because the library is pre-built. So perhaps it?s an os/arch incompotibility. If you have detailed logs, please raise a ticket for us to investigate)

vince.lee
2021-06-01 12:50
~where can i find these iso date format matchers?~ found them

todd.lemmonds
2021-06-01 15:57
has joined #pact-js

alexander.infante
2021-06-01 15:57
has joined #pact-js

michael.doyle
2021-06-01 15:58
has joined #pact-js

ashish.joshi
2021-06-01 18:09
hi All, While using pact `Matchers`, is there a way to set `eachLike` with min of zero? The case i want match is, the value to the required property can be either an empty array or with multiple elements. if I use `like` with empty array it is only matches empty array.

ashish.joshi
2021-06-01 18:10
Any views on this :point_up:

paulorochag
2021-06-01 20:20
has joined #pact-js

matty_o_connor01
2021-06-01 20:33
I can't replicate that `Error [ERR_UNHANDLED_ERROR]: Unhandled error` now. :face_with_raised_eyebrow: Should I still raise something regarding the `jest-pact` and `@pact-foundation/pact` betas doesn't appear to solve the file length issue on windows? The versions tried were `10.0.0-beta.36` for `@pact-foundation/pact` and `0.9.0-beta.v3` for `jest-pact`.

matt.fellows
2021-06-01 22:23
It might be a jest pact issue, 100% certain the beta package solves path length issue. You need to import the v3 package path which uses the new rust core

matt.fellows
2021-06-01 22:23
If you don't use the v3 path import it tries to use the existing interface

matt.fellows
2021-06-01 22:24
No you can't

matt.fellows
2021-06-01 22:25
You need to write two separate tests for each case

matt.fellows
2021-06-01 22:25
See optional attributes in docs

sheyan.rizfee
2021-06-02 01:16
@here

matt.fellows
2021-06-02 01:16
We don?t allow that Sheyan - there is 1000 people in this channel!

sheyan.rizfee
2021-06-02 01:19
Hi All, could i find a sample project or documentation to create a mock provider using OpenAPI specs

matt.fellows
2021-06-02 01:20
what have you read so far and tried to do?

matt.fellows
2021-06-02 01:23
Are you referring to Pactflow?s bi-directional contracts feature, or something else?

sheyan.rizfee
2021-06-02 01:24
read this https://pactflow.io/blog/contract-testing-using-json-schemas-and-open-api-part-1/ We would have a consumer who will be a Polling service which will hit the provide.. Devs have provide me the openapi specs to create a mock service.

matt.fellows
2021-06-02 01:25
We don?t have a mock service for OpenAPI specs

matt.fellows
2021-06-02 01:25
What gave you the impression in that article that we do? Perhaps I need to update/clarify it?

matt.fellows
2021-06-02 01:26
Pactflow has some tools for this space: https://pactflow.io/blog/bi-directional-contracts/

matt.fellows
2021-06-02 01:26
but it doesn?t provide a mock using an OAS

sheyan.rizfee
2021-06-02 01:26
sure will have a look

matt.fellows
2021-06-02 01:26
It provides contract testing capability that let?s you use the OAS as a contract

tjones
2021-06-02 11:16
```let foo = { a: [{ id: 'test'}] } like(foo)``` I think this will not match if your provider returns: ```{ a: [{ id: 'test'}, {id: 'test'}] }``` whereas the eachLike version will pass.

matt.fellows
2021-06-02 11:18
it should, because the like matcher cascades to all elements, including arrays

jaspal.gill
2021-06-02 15:23
has joined #pact-js

wenqiglantz
2021-06-02 18:19
has joined #pact-js

ch.toimbetov
2021-06-02 21:46
has joined #pact-js

kyle.florence
2021-06-03 04:57
@kyle.florence has left the channel

xyz1kind
2021-06-03 05:03
has joined #pact-js

aftab.shamim2020
2021-06-03 06:02
has joined #pact-js

slu.mendozaharold
2021-06-03 10:33
has joined #pact-js

todd.lemmonds
2021-06-03 18:38
Hello Everyone - I'm having a couple issues getting everything setup that hopefully someone has some ideas on.

todd.lemmonds
2021-06-03 18:40
1. in the example-consumer project, I keep getting the following error

todd.lemmonds
2021-06-03 18:40
? example-consumer git:(master) ? make test ========== STAGE: test (pact) ========== npm run test:pact > consumer@0.1.0 test:pact /Users/tlemmonds/Workspace/example-consumer > cross-env CI=true react-scripts test --testTimeout 30000 pact.spec.js FAIL src/api.pact.spec.js ? Test suite failed to run TypeError: Cannot read property 'endsWith' of undefined 10 | url = process.env.REACT_APP_API_BASE_URL; 11 | } > 12 | if (url.endsWith("/")) { | ^ 13 | url = url.substr(0, url.length - 1) 14 | } 15 | this.url = url at new API (src/api.js:12:13) at Object.<anonymous> (src/api.js:48:16) at Object.<anonymous> (src/api.pact.spec.js:2:1) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.806s, estimated 3s Ran all test suites matching /pact.spec.js/i. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! consumer@0.1.0 test:pact: `cross-env CI=true react-scripts test --testTimeout 30000 pact.spec.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the consumer@0.1.0 test:pact script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/tlemmonds/.npm/_logs/2021-06-03T18_39_49_610Z-debug.log make: *** [test] Error 1

todd.lemmonds
2021-06-03 18:41
Once I comment out lines 12 to 15, everything works

todd.lemmonds
2021-06-03 18:42
~2. Second issue is when I run the npm start command to startup the api, they api just shows the sad panda~

todd.lemmonds
2021-06-03 18:42
we figured this on out

tjones
2021-06-04 00:02
Glad you've solved it! I'm curious where the example came from? I don't think we have a react example, and it would be good to have one

sergio.artero
2021-06-04 10:07
has joined #pact-js

v-gabriel.dantas
2021-06-04 15:26
has joined #pact-js

todd.lemmonds
2021-06-04 16:24
We solved issue #2

todd.lemmonds
2021-06-04 16:24
still wondering about issue 1


leonardo.viana
2021-06-04 18:52
has joined #pact-js

tonynguyenit18
2021-06-04 22:43
Hi @todd.lemmonds For issue number 1 Seem like the code does not receive env variable configured in Makefile, try to add this on top of the file ```#!make include .env```

matt.fellows
2021-06-05 00:11
`make test`

matt.fellows
2021-06-05 00:11
It needs the environment variable, and make adds it by default. Alternatively you may export it

matt.fellows
2021-06-05 00:11
The instructions should say that, if not please raise an issue so we can clarify

todd.lemmonds
2021-06-05 20:30
This worked. Thank you @tonynguyenit18

todd.lemmonds
2021-06-05 20:31
@v-gabriel.dantas ^^

github2
2021-06-06 03:26
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.37_ published by github-actions[bot]

ashish.joshi
2021-06-07 06:09
:thank_you:

yashdev963
2021-06-07 06:51
has joined #pact-js

dimundo
2021-06-07 10:51
hi! i?ve https://github.com/pact-foundation/pact-js/tree/master/examples/messages funny thing, tests are passing for ``` .withContent({ id: like(1), surname: like("rover"), type: term({generate: "bulldog", matcher: "^(bulldog|sheepdog)$"}), })``` and ``` .withContent({ type: term({generate: "bulldog", matcher: "^(bulldog|sheepdog)$"}), })```

dimundo
2021-06-07 10:52
am i doing something wrong ? ```export function dogApiHandler(dog: any): void { if (!dog.id && !dog.name && !dog.type) { throw new Error("missing fields") }``` wrong/not existing fields doesnt fail

tjones
2021-06-07 10:53
Is your second test skipped still? (it starts off skipped in the example)

dimundo
2021-06-07 10:53
skipped, yes

tjones
2021-06-07 10:53
then it?s not being run :slightly_smiling_face:

tjones
2021-06-07 10:56
If that?s not the problem, can you share the whole test?

dimundo
2021-06-07 10:57
just cloned

dimundo
2021-06-07 10:57
uncommented 2nd test ? `npm run test:consumer` ? 2 tests are passing

tjones
2021-06-07 10:58
Yep, you?re right.

dimundo
2021-06-07 10:59
volkswagen tests ?

tjones
2021-06-07 10:59
volkswagen?

dimundo
2021-06-07 10:59
always green :slightly_smiling_face:

tjones
2021-06-07 11:00
Heh. Ok, so > am i doing something wrong ? I don?t know, but your understanding matches mine, if you are, we?re both doing it.

tjones
2021-06-07 11:00
I?m just making dinner, I?ll take a look after


tjones
2021-06-07 11:06
oh wait

tjones
2021-06-07 11:06
the consumer code is wrong

tjones
2021-06-07 11:06
``` if (!dog.id || !dog.name || !dog.type) {``` ^ Should be this

tjones
2021-06-07 11:08
Good find! Fixed in master.

dimundo
2021-06-07 11:11
super, it is

tjones
2021-06-07 11:13
Oh man, this is amazing :joy:


dimundo
2021-06-07 11:16
anyone connected with both ws and scala here mayebe? #pact-scala-itv is quite silent :disappointed:


dimundo
2021-06-07 11:17
websockets

tjones
2021-06-07 11:17
I know that the scala pact implementation is a fair bit behind the rest of them

dimundo
2021-06-07 11:17
:disappointed:

tjones
2021-06-07 11:18
Last time I did scala, we used pact-jvm in groovy to trigger the scala consumers

tjones
2021-06-07 11:18
or maybe that was the provider (it was a while ago, sorry)

tjones
2021-06-07 11:18
Try asking in #general or #pact-jvm

dimundo
2021-06-07 11:20
will try in jvm, hoping noone will kick me because of spam :slightly_smiling_face:

dimundo
2021-06-07 11:20
thank you again :slightly_smiling_face:

tjones
2021-06-07 11:21
I don?t think that?ll happen if you?re asking questions about pact. And, you?re welcome!

tjones
2021-06-07 11:21
(we haven?t really had trouble with spammers, so I think we don?t have any automated moderating tools)


dimundo
2021-06-07 11:52
will talk to our scala guys ( not sure if they will be happy about groovied java :smile: )

i.pinzari
2021-06-07 17:27
has joined #pact-js

pedroefajardo_pactio
2021-06-07 17:55
ok, so,sI finally had time to finish one GraphQL consumer test and it is being published to a Dockerized version of the Broker, everything running on local as of now. Now I am ready to run the provider side of the tests. I understand better now what you meant above by ?framework-free? approach. Add a test-only state change endpoint to the provider code, specify what the end point is in the consumer side Run the provider Run the verifier Cool. The other question i have is regarding provider state. If I set the provider state, for example to return `query { user { name age } }` this is what the provider will return when the interaction in the Pact is executed. How does this test against what the provider will actually return? Say the provider changed the return to: `query { user { lastName age } }` since I am ?injecting? the provider state and this provider state is what the provider verifier would see and return wouldn?t the tests pass always?

caiquedpfc
2021-06-07 18:57
Hello everyone, I'm having some problems generating my contract test in javascript, I put the problem I'm facing on stackoverflow, in case anyone knows how to solve the link to my question on stackoverflow is below. In short, I'm getting Missing requests error and error Cross origin http://localhost forbidden when I run npm run test:consumer. https://stackoverflow.com/questions/67876713/pact-io-getting-missing-requests-error-and-error-cross-origin-http-localhost

gurkiratguliani
2021-06-07 19:36
has joined #pact-js

matt.fellows
2021-06-07 22:06
Is this just a standard jest test or are you actually running in a browser?

caiquedpfc
2021-06-08 00:24
Hi Matt, how are you? I hope you are well :smile: this just a standard jest test

matt.fellows
2021-06-08 00:54
hmm

matt.fellows
2021-06-08 00:55
cors error seems non pact related then

matt.fellows
2021-06-08 00:55
that being said, there is a ?cors? setting you could try adding to see if it helps (i.e. it would allow the `OPTIONS` request)

matt.fellows
2021-06-08 01:39
Can you please show the code for this? ```import { request } from './requests';```

matt.fellows
2021-06-08 01:39
I assume it?s an axios import

matt.fellows
2021-06-08 01:40
```axios.defaults.adapter = require('axios/lib/adapters/http');``` happens after importing your `viewApi` code, so the default adapter may not actually have any impact on the imported axios client

matt.fellows
2021-06-08 01:44
I?ve posted an answer, but I think just adding `cors: true` will fix it in your case

billal.patel
2021-06-08 10:55
Hi there, I am having some trouble which I haven?t seen before. Any ideas:

krishna.ramnk
2021-06-08 13:24
has joined #pact-js

sagar.kharab
2021-06-09 00:32
has joined #pact-js

sagar.kharab
2021-06-09 00:38
Hi @matt.fellows: I think I am having same issue so just to confirm my consumer let say called A and I am setting up pact using ```pact_oauth = Consumer('Consumer').has_pact_with(Provider('Provider'), host='my.real.deployed.host.name' version='3.0.0', port=443, use_mocking_server=True)``` In this case if likely to happen that the request will hit the real server and not the mock setup for this e.g. ```exp_response = { "access_token": "token", "expires_in": 120, "token_type": "Bearer" } parameter = {} (pact. given('Many people exists in database') .upon_receiving('a request for token') .with_request('POST', '/oauth/token', body=parameter, headers={'content-type': 'application/json'}) .will_respond_with(200, body=exp_response))``` Any guidance will be great, Please let me know if there are any queries.

matt.fellows
2021-06-09 00:40
you need your consumer test to communicate to the mock server, not the real one

matt.fellows
2021-06-09 00:41
that means you must have control over the API client that makes the call, and configure it during the test phase to point at the pact mock server, not the real one

sagar.kharab
2021-06-09 00:48
I understand but the test uses a dependency, thst makes an external call and that external call is configured weirdly that it can't be overridden straight forward so just wondering that if my pact declaration has the host name as same host name, it's not going to hit mock but hit actual url?

matt.fellows
2021-06-09 00:49
This looks like a consumer test. You can?t configured the host to be your server, because your server is not Pact, so it cannot receive the messages

matt.fellows
2021-06-09 00:49
Is this Python code?

matt.fellows
2021-06-09 00:50
perhaps worth asking in there if there is a way to intercept the request during test and redirect to Pact instead

sagar.kharab
2021-06-09 00:51
yea it is python code. I just searched for actual url and found this post closest. I will head over there

abubics
2021-06-09 02:43
"Checksum rejected" is probably the key takeaway there. Maybe check that the `.tar.gz` file is a valid archive? Do you always get the same error?

david.vancouvering
2021-06-09 03:36
has joined #pact-js

david.vancouvering
2021-06-09 03:41
Hey, all! Really great to see a Slack channel. I am running a pact-js consumer test, but I keep getting an error saying connection refused when my test tries to connect to the mock server. And then the Pact verifier fails saying the expected method was never called. I have tried both V2 and V3 with same result. My Google research told me to try turning on debug logs and to run the mock service from the command-line. Did those, nothing in the logs, and the service runs fine from the command-line. I stopped the test in the debugger when my test runs, and checked to see if there was a service listening on the configured port. There was not. Here is my Pact configuration: ``` const provider = new PactV3({ consumer: "viewitem_nodestar", provider: "viexpio", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });``` Here is my test: ``` before(() => { provider .given(`item id ${itemId} exists`) .uponReceiving("a request for the VLS module") .withRequest({ method: "GET", path: `/experience/listing_details/v2/module_provider/${itemId}`, headers: {Accept: "text/event-stream"} }) .willRespondWith({ status: 200, headers: {"Content-Type": "text/event-stream"}, body: EXPECTED_BODY }); }); it('It does nothing yet', async (done) => { try { await provider.executeTest(async () => { const arg = {req: baseRequest, res: baseResponse}; expsvcio.responseHandler(arg, {}); try { await baseResponse.on('finish', function (response) { console.log(response); done(); }); } catch (e) { console.log(e); } }); } catch (e) { console.log(e); } });```

david.vancouvering
2021-06-09 03:42
Here's the error I get: ```Error: Test failed for the following reasons: Test code failed with an error: Mock server failed with the following mismatches: 0) The following request was expected but not received: Method: GET Path: /experience/listing_details/v2/module_provider/100750056032 Headers: Accept: text/event-stream RuntimeError: Re-thrown: Host: http://localhost:8081, error: connect ECONNREFUSED 127.0.0.1:8081```

uglyog
2021-06-09 03:43
Run with LOG_LEVEL=debug and see what the logs are

matt.fellows
2021-06-09 03:43
I don't see where you actually start the mock server? I.e. setup)

david.vancouvering
2021-06-09 03:43
Yea I did that, and the log is empty :disappointed:

david.vancouvering
2021-06-09 03:44
``` const provider = new PactV3({ consumer: "viewitem_nodestar", provider: "viexpio", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });```

matt.fellows
2021-06-09 03:44
Also the code in the before block is a promise, you should return it or await ir

matt.fellows
2021-06-09 03:44
That doesn't start it

david.vancouvering
2021-06-09 03:44
OK. I am new to nodejs and promises are breaking me

david.vancouvering
2021-06-09 03:44
Oh

david.vancouvering
2021-06-09 03:44
one sec

matt.fellows
2021-06-09 03:44
`setup()`

david.vancouvering
2021-06-09 03:44
I'm using V3

matt.fellows
2021-06-09 03:44
Ah

david.vancouvering
2021-06-09 03:44
There is no setup as far as I can see

david.vancouvering
2021-06-09 03:45
I upgraded to V3 to see if the problem would get resolved

matt.fellows
2021-06-09 03:45
My apologies I didn't notice that

david.vancouvering
2021-06-09 03:45
Let me try returning in the before

david.vancouvering
2021-06-09 03:45
Same errors

david.vancouvering
2021-06-09 03:46
If it's helpful, no pact file is being written to my pacts directory either, although the directory does get created

uglyog
2021-06-09 03:46
Regardless, `provider.executeTest` should print something out if the `LOG_LEVEL` environment variable is set to something

david.vancouvering
2021-06-09 03:46
I have it set to debug :disappointed:

david.vancouvering
2021-06-09 03:47
``` const provider = new PactV3({ consumer: "viewitem_nodestar", provider: "viexpio", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });```

david.vancouvering
2021-06-09 03:47
Oh LOG_LEVEL env variable I was unaware of that

david.vancouvering
2021-06-09 03:47
Let me set that

matt.fellows
2021-06-09 03:47
so which part of your code actually sends the request to `localhost:8081/experience?`

uglyog
2021-06-09 03:48
@matt.fellows we need to fix that log config

matt.fellows
2021-06-09 03:48
yeah

david.vancouvering
2021-06-09 03:48
```[2021-06-09T03:47:49Z DEBUG pact_mock_server::mock_server] Started mock server on 0.0.0.0:8081 [2021-06-09T03:47:49Z DEBUG pact_mock_server::server_manager] Shutting down mock server with ID 26475568fac948778d125eb1b1932167 - MockServerMetrics { requests: 0 } [2021-06-09T03:47:49Z DEBUG pact_mock_server::mock_server] Mock server 26475568fac948778d125eb1b1932167 shutdown - MockServerMetrics { requests: 0 } Error: Test failed for the following reasons:```

matt.fellows
2021-06-09 03:48
it?s on the TODO

david.vancouvering
2021-06-09 03:48
So it started, and then it immediately shut down ?

matt.fellows
2021-06-09 03:48
I?m not sure this does what you think it does ``` await baseResponse.on('finish', function (response) { console.log(response); done(); });```

david.vancouvering
2021-06-09 03:48
Haha tell me about it

david.vancouvering
2021-06-09 03:48
I think it both does and does not do what I think it does, because I don't understand it lol

matt.fellows
2021-06-09 03:48
that looks like you?ve combined an event handler (i.e. the `.on`) bit, and promises

david.vancouvering
2021-06-09 03:49
So I am using an internal library which is based on event emitters

matt.fellows
2021-06-09 03:50
What I think is happening, is that the `it` block fires immediately returns and then the mock service shuts down, but then your api client issues the call, but the server is shut down by then

matt.fellows
2021-06-09 03:50
`async (done)`

matt.fellows
2021-06-09 03:50
also that doesn?t look rigth :stuck_out_tongue:

david.vancouvering
2021-06-09 03:50
Haha I am so sorry you guys I have been flailing with promises and events

matt.fellows
2021-06-09 03:50
yes, both by themselves are confusing, let alone combined

david.vancouvering
2021-06-09 03:51
From what I can see looking at our code, I send the GET request, and the result is published as an event, which is processed, and the data is put into a response object. That response object itself is an event emitter which emits a 'finish' event when it gets the final result from our internal client.

matt.fellows
2021-06-09 03:51
my suggestion - comment out the event code for now. Use a standard HTTP library (e.g. axios) and get the pact test to pass.

matt.fellows
2021-06-09 03:51
that way you?re only spinning one or two plates

david.vancouvering
2021-06-09 03:51
Ah interesting

matt.fellows
2021-06-09 03:51
once it passes, get your code in there, and iterate until it works

matt.fellows
2021-06-09 03:51
too many moving parts and new ideas = :exploding_head:

david.vancouvering
2021-06-09 03:52
I am pretty sure that the service is working. I think where I'm stuck is how do I make sure I wait until the event completes before I exit the test method

david.vancouvering
2021-06-09 03:52
I was trying to use async/await but apparently that doesn't work for events

david.vancouvering
2021-06-09 03:52
I did lots of digging on how to write tests against events but could find nothing useful on the interwebs

david.vancouvering
2021-06-09 03:54
But I'll do as you suggest, and we'll see. Turning on the LOG_LEVEL let me see the service start, which gives me confidence that it's not Pact but the way I'm writing my test

david.vancouvering
2021-06-09 03:54
One question I have: I would expect, when I break in my test code, that the mock service should be running. But when I do, it is not. Do you know why that might be?

david.vancouvering
2021-06-09 03:55
"break" meaning "stop in my debugger inside my test method"

matt.fellows
2021-06-09 03:55
I suspect there are reasons for that relating to the event loop and the execution into the rust engine

matt.fellows
2021-06-09 03:55
```it('It does nothing yet', () => { provider.executeTest(() => { return new Promise((resolve, reject) => { const arg = {req: baseRequest, res: baseResponse}; expsvcio.responseHandler(arg, {}); baseResponse.on('finish', function (response) { // check response to make sure it works OK / finish the unit test resolve("it all did what I hoped it would do...") // reject("things went badly, fail the test") }); }) }); });```

matt.fellows
2021-06-09 03:56
something like that (^^ untested, but hopefully gives you an idea to go about wrapping an event emitter into a promise)

david.vancouvering
2021-06-09 03:56
Ah...

david.vancouvering
2021-06-09 03:56
So what I see you saying here is that mocha knows how to handle Promise objects and will do the right thing

matt.fellows
2021-06-09 03:56
(updated to show the failure case)

matt.fellows
2021-06-09 03:57
yes, most frameworks natively handle promises

david.vancouvering
2021-06-09 03:57
ah ok somehow I missed that when studying mocha, that makes a lot of sense though

david.vancouvering
2021-06-09 03:57
OK thanks Matt, much appreciated, let me give this a go

matt.fellows
2021-06-09 03:57
`async/await` is simply sugar for handling promises, ultimately it gets converted into `thing().then(anotherThing).then(?)`

david.vancouvering
2021-06-09 04:06
That was great, it got rid of the connection refused error and the verification errors. But what's weird is that even if I don't call my internal client code to send an HTTP request, Pact still doesn't report any errors. Shouldn't it fail saying the expected request was not sent to the mock service?

matt.fellows
2021-06-09 04:08
oh my badness, Let me move that code into an IDE and fix the promise error I gave you :stuck_out_tongue:

matt.fellows
2021-06-09 04:09
(we need to return the `provider.executeTest(?)` bit)

david.vancouvering
2021-06-09 04:09
oh I can fix that

david.vancouvering
2021-06-09 04:10
There we go

matt.fellows
2021-06-09 04:10
cool

matt.fellows
2021-06-09 04:10
error showing up?

david.vancouvering
2021-06-09 04:10
```RuntimeError: Re-thrown: Host: http://localhost:8081, error: {"error":"Unexpected-Request : Request { method: \"GET\", path: \"/experience/listing_details/v2/module_provider\", query: Some({\"shippingServiceCode\": [\"item547fca9d06:g:20UAAOSwQ9ldG5Ne\"], \"variationId\": [\"1234567\"], \"itemId\": [\"100750056032\"], \"modules\": [\"VLS\"], \"vero\": [\"false\"]}), headers: Some({\"connection\": [\"close\"], \"accept\": [\"text/event-stream\"], \"user-agent\": [\"service-instruments-ebay/4.9.5 (x64-darwin) node/14.15.4\"], \"host\": [\"localhost:8081\"], \"x-ebay-consumer-id\": [\"urn:ebay-marketplace-consumerid:31be3645-70d4-467d-a381-1d97473133f4\"], \"content-type\": [\"application/json\"], \"x-ebay-client-app-name\": [\"r1vinode\"], \"x-ebay-tf-authorization\": [\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRldmtpZCIsIng1dSI6ImludGVybmFsOi8vZGV2Y2VydCJ9.eyJyZWFsbSI6ImRldiIsImF1ZCI6WyJmaWRlbGl1cyIsInBhdHJvbnVzIl0sImluc3RhbmNlcyI6WyIxOTIuMTY4Ljg2LjIzMiJdLCJpYXQiOjE2MjMyMTE3ODMsIm5iZiI6MTYyMzIxMTc4MywiZXhwIjoxNjIzMjk4MTgzLCJpc3MiOiJ0cnVzdGZhYnJpYyIsInN1YiI6InIxdmlub2RlIn0.V8ja1GEhiBEALWTdA3jMhvBC5VyqfQq_4bihXS-zKRLbRApZLSNbLLQ3z7AEJg43MLrsOrkCX5QocENsbaIqBVWtjXdRARjsD81j2ifdk01aI8RGD5R8CwxxgSRlqJElOz5cYyMymfg8xUtrXncFbgPdJxYiHZmx9IU_hdX6AgGFe9eTMRESGU5jGDley4HkCOnoc4lWqb_qpUvntjWvX3x7HCdFfEj5RBhIX5fBKU3ImIQ8OjcQP9oUywS_wnbzY-rpf3wHO9-a9n0dSQOUUEVmM6U09S6mjDyBeYTqdjD1xOBras4szxu7mJSeBgiSTTFC6VtBYJBu_zGIGjYkZw\"]}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }"}```

david.vancouvering
2021-06-09 04:11
Now we're talking.

david.vancouvering
2021-06-09 04:11
One thing that's concerning - at the bottom of the error it seems to say the MatchingRules is empty ({})

matt.fellows
2021-06-09 04:11
:ok_hand:

david.vancouvering
2021-06-09 04:11
Shouldn't that have the rules I set up prior to running the test?

david.vancouvering
2021-06-09 04:12
``` before(() => { provider .given(`item id ${itemId} exists`) .uponReceiving("a request for the VLS module") .withRequest({ method: "GET", path: `/experience/listing_details/v2/module_provider/${itemId}`, headers: {Accept: "text/event-stream"} }) .willRespondWith({ status: 200, headers: {"Content-Type": "text/event-stream"}, body: EXPECTED_BODY }); });```

matt.fellows
2021-06-09 04:12
what is in `EXPECTED_BODY` ?

david.vancouvering
2021-06-09 04:12
It's a wad of JSON

matt.fellows
2021-06-09 04:12
any pact matchers in it?

david.vancouvering
2021-06-09 04:12
Yes

david.vancouvering
2021-06-09 04:12
``` const EXPECTED_BODY = { chunks: [ { "type": "DATA", "id": like("123"), "data": { "modules": { "VLS": { "_type": "VLSViewModel", "listing": like({ "listingId": "300017681384", "version": 0, "title": { "content": "a title" } } ) } } } } ] };```

matt.fellows
2021-06-09 04:13
:thinking_face:

david.vancouvering
2021-06-09 04:13
But it looks like the server rejected the incoming request as being unexpected

matt.fellows
2021-06-09 04:13
Let?s see what happens when it passes

david.vancouvering
2021-06-09 04:13
So I am not sure how the body plays into it

david.vancouvering
2021-06-09 04:14
Oh ah I see more errors below, where Pact is saying "I didn't get this GET request, but I got this unexpected one"

david.vancouvering
2021-06-09 04:14
So I think I'm good

david.vancouvering
2021-06-09 04:15
Sweet. Once I get this working it's going to be a big win.

david.vancouvering
2021-06-09 04:15
Great tool you all have, solves a major problem!

matt.fellows
2021-06-09 04:18
:raised_hands::raised_hands::raised_hands:

david.vancouvering
2021-06-09 04:29
Which do you recommend right now in terms of overall stability and support - standard pact-js or V3? For example, I'm trying to find information on how to do a regex for the query string and all the docs and examples I can find are for the (v2) pact-js

matt.fellows
2021-06-09 06:45
All of the examples/tutorials will currently be v2 because it?s the current stable

matt.fellows
2021-06-09 06:45
as per the note in the readme, V3 is production ready in the sense that it works. But the API is likely to change, so if you can handle a bit of refactoring you could stick with the V3 version

nuno.pik
2021-06-09 06:58
has joined #pact-js

tjones
2021-06-09 08:15
Usually we see this when there?s a proxy that is blocking the download (or causing the download to respond with a login page)

billal.patel
2021-06-09 08:51
Thanks guys. It somehow resolved itself so must have been an internet or temporary permissions issue

tjones
2021-06-09 09:16
Sorry, I didn?t see this. The log level you need is `debug`, not trace. The documentation was wrong and has now been corrected.

tjones
2021-06-09 09:17
(also there was a bug with incorrectly passing `trace` down to the pact ruby service. But it doesn?t matter, because `trace` isn?t really used for anything that you?d need)

tjones
2021-06-09 10:08
(I mean, we should still fix that)

natashakdykes
2021-06-09 16:06
has joined #pact-js

torbjorn.vatn
2021-06-09 17:30
has joined #pact-js

s.goel
2021-06-10 08:57
has joined #pact-js

kondal.ramidi
2021-06-10 16:13
has joined #pact-js

dimundo
2021-06-10 18:06
hi! i?m checking ( again :smile: ) message tests examples ``` describe("receive dog event", () => { it("accepts a valid dog", () => { return messagePact .given("some state") .expectsToReceive("a request for a dog") .withContent({ id: like(1), name: like("rover"), type: term({ generate: "bulldog", matcher: "^(bulldog|sheepdog)$" }), }) .withMetadata({ "content-type": "application/json", }) .verify(synchronousBodyHandler(dogApiHandler)) }) })``` any options to verify also `metadata` in `dogApiHandler` ?

matt.fellows
2021-06-10 21:05
not in Pact JS at the moment sorry

matt.fellows
2021-06-10 21:06
oh, this is a consumer test

matt.fellows
2021-06-10 21:06
If you could please raise an issue, it should be doable I think

richard
2021-06-11 00:13
has joined #pact-js


jwcarman
2021-06-11 14:23
has joined #pact-js

hello370
2021-06-11 14:58
has joined #pact-js

david.vancouvering
2021-06-11 23:23
Hey, I am trying to write a consumer test for a server-sent event (SSE endpoint). In this case the HTTP code is 200, the Content-Type response header is `text/event-stream` and the response body is of the form ```data: {some: "json"}\n\n```

david.vancouvering
2021-06-11 23:24
My question is: how do you do matching of the body when it's not JSON but a raw string with newlines that happens to contain JSON embedded in it?

david.vancouvering
2021-06-11 23:25
I tried to put the newlines directly in the sample above but Slack keeps getting rid of them

david.vancouvering
2021-06-11 23:26
Here's the Pact file that is generated with a successful run, but notice there is no matching logic in the response, so if the provider doesn't respond exactly with the same data the provider verification test will fail :disappointed: ``` "response": { "body": "data: { \"modules\": { \"VLS\": { \"_type\": \"VLSDataModule\",\"viewListingServiceResponse\":\"anything\",\"meta\":{\"name\":\"VLS\"}}},\"meta\":{\"pageTitle\":\"VI\",\"pageTemplate\":{\"_type\":\"PageTemplate\",\"templateId\":\"VI\"}}}\n \n ", "headers": { "Content-Type": "text/event-stream", "transfer-encoding": "chunked" }, "status": 200 }```

david.vancouvering
2021-06-11 23:27
So say I want to match `anything` to any string. Do I need to make the whole thing a big regex?

david.vancouvering
2021-06-11 23:54
I used `regex` for now, lmk if there is a better approach

david.vancouvering
2021-06-12 02:28
Regex sadly only takes you so far. I want to express that the response can contain an array of one or more items. I can't use any of those cool matchers to express that. :disappointed:

matt.fellows
2021-06-12 03:15
Yeah the matchers only work for JSON (and in some cases XML) payloads

matt.fellows
2021-06-12 03:15
One option would to be to write a little adapter on either side of the tests to convert into your different format

vikrant82
2021-06-12 12:16
has joined #pact-js

thanuxxxx
2021-06-14 02:18
Hi everyone, I have a field which may contains zero or more elements (as an array) can I use `eachLike` from `Matches`?

matt.fellows
2021-06-14 03:04
No you have to write two tests. EachLike has a minimum of one element


thanuxxxx
2021-06-14 03:06
Got it. I just fond that article, and it make sense. Thank you

matt.fellows
2021-06-14 04:39
:+1:

daniel.bubenheim
2021-06-14 08:05
has joined #pact-js

joaoproenca
2021-06-14 10:15
has joined #pact-js

thanuxxxx
2021-06-14 13:54
Is this also true for a scenario where a field is always exists but the value can be an empty array or non-empty array?

matt.fellows
2021-06-14 14:09
Yep

matt.fellows
2021-06-14 14:10
If we never test one of those scenarios we can't be confident the contract is safe

leonardo.viana
2021-06-14 15:24
@matt.fellows, did the behavior of `eachLike` change with V3? I ask because if you look at the documentation for Pact JS V3, you will see that there?s a new `MatchersV3.atLeastOneLike` which seems to differ with respect to `MatchersV3.eachLike` exactly because it also validates that there?s a least 1 item in the list: https://github.com/pact-foundation/pact-js#pact-js-v3 ```eachLike: Applies the type matcher to each value in an array, ensuring they match the template. Note that this matcher does not validate the length of the array, and the items within it. atLeastOneLike: Behaves like the eachLike matcher, but also applies a minimum length validation of one on the length of the array. The optional count parameter controls the number of examples generated.```

thanuxxxx
2021-06-14 16:20
I have a response object with nested objects, how should I verify that? I mean do to do a `toHaveProperty` for each and every property in the response?

e.pittaluga.b
2021-06-14 16:34
has joined #pact-js

npatil
2021-06-14 17:28
has joined #pact-js

david.vancouvering
2021-06-14 19:57
Thanks, Matt. I'm not following the adapter approach. Oh you mean run a small passthrough server that converts the JSON payload from the mock service to an SSE payload. I'd need to do the same thing for the provider side, where I convert the SSE payload to JSON so the verifier works. Maybe enhance the Pact mock service and Pact client to support pre- and post- filter plugins. Would that be an interesting pull request for y'all?

thanuxxxx
2021-06-14 20:55
Why I am getting this error `pact-node@10.12.2: Pact Binary Error: WARN: Only the first item will be used to match the items in the array at $['body']['tipSuggestions'].` 1. When I delete the pact folder, then run the tests, I don't see the error (first time) I am using Pact with Jest

matt.fellows
2021-06-14 21:49
Can you please share the code?

matt.fellows
2021-06-14 21:49
I'm guessing you're passing an array of items to EachLike with different values

matt.fellows
2021-06-15 00:20
`eachLike` should also have had a minimum of 1


matt.fellows
2021-06-15 00:20
`atLeastOneLike` makes it clearer what it does, because there are new matchers that limit the max etc.

dimundo
2021-06-15 06:11
hi! if app is consumer of n pacts, it means, that in ci/cd one must run `can-i-deploy` for each consumer ? any wildcards/lists/arrays/extra params/name it available ?

dimundo
2021-06-15 06:15
lets say there is frontend part, which is ? api consumer ? message consumer so, 2 pacts in total, to check

dimundo
2021-06-15 06:16
this checks only API part `"can:i:deploy:consumer": "pact-broker can-i-deploy --pacticipant 'APIConsumerJSApp' --pacticipant 'APIProviderScalaApp' --latest ....",`

dimundo
2021-06-15 06:17
so, either 2 checks or ? ?

matt.fellows
2021-06-15 06:18
Do you deploy both consumers at the same time?

matt.fellows
2021-06-15 06:19
Usually that check is in the CD pipeline for the app that's being deployed

dimundo
2021-06-15 06:19
its a single app

dimundo
2021-06-15 06:19
so - yes

matt.fellows
2021-06-15 06:19
That's unusual

matt.fellows
2021-06-15 06:19
Why deploy them together?

matt.fellows
2021-06-15 06:19
But it doesn't matter

dimundo
2021-06-15 06:20
why ? frontend, which utilizes regular APIs + communication over websockets

matt.fellows
2021-06-15 06:20
In your case I'd need to check the args, that might not automatically pick up its dependencies (i.e. providers)

matt.fellows
2021-06-15 06:21
Just double check. You might need to actually call the command twice

abubics
2021-06-15 06:22
historically, the message consumer can't be bundled with the http consumer, so even though it's conceptually one consumer, it's split into 2 contracts . . . right?

dimundo
2021-06-15 06:22
2 contracts - right, 1 app - right

dimundo
2021-06-15 06:23
but if app gets APIs from n providers ? we are in microservices era

abubics
2021-06-15 06:25
I'm just clarifying for what seems like some confusion on Matt's end ("That's unusual" & "Why deploy them together?")

dimundo
2021-06-15 06:26
looks like for n pacts/contracts, one must do n checks for `"can:i:deploy:consumer"` with each pact pair

abubics
2021-06-15 06:28
you should only need to do multiple if the pacticipant has multiple handles (2 consumer identifiers in this case)

abubics
2021-06-15 06:29
in the usual case, a particular codebase only has one identifier, so it only needs to specify itself once


dimundo
2021-06-15 06:30
`consumers: List[String]` list here sounds logical - like i?m provider of list consumers - lets check them all

dimundo
2021-06-15 06:32
js consumer pacts folder

dimundo
2021-06-15 06:34
so i publish them and provider fetches them and checks both

dimundo
2021-06-15 06:37
but looks like i need to make 2 checks `"can:i:deploy:consumer:messages"` and `"can:i:deploy:consumer:api"`

dimundo
2021-06-15 06:38
yeah right, from one side it could be handy to check in one bunch, from other side - error message if something fails is more obvious in discrete checks

matt.fellows
2021-06-15 06:41
From `pact-broker help can-i-deploy` ```#### Recommended usage - allowing the Pact Broker to automatically determine the dependencies Prerequisite: if you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know which version of each application is in that environment. How you do this depends on the version of the Pact Broker you are running. If you are using a Broker version where deployment versions are supported, then you would notify the Broker of the deployment of this application version like so: $ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment test This assumes that you have already set up an environment named "test" in the Broker. If you are using a Broker version that does not support deployment environments, then you will need to use tags to notify the broker of the deployment of this application version, like so: $ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test Once you have configured your build to notify the Pact Broker of the successful deployment using either method describe above, you can use the following simple command to find out if you are safe to deploy (use either `--to` or `--to-environment` as supported): $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION [--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG ] --broker-base-url BROKER_BASE_URL If the `--to` or `--to-environment` options are omitted, then the query will return the compatiblity with the overall latest version of each of the other applications. Examples: Can I deploy version 173153ae0 of application Foo to the test environment? $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \ --to-environment test \ --broker-base-url https://my-pact-broker```

dimundo
2021-06-15 06:42
yes, i read https://docs.pact.io/pact_broker/can_i_deploy/ , but its for simple 1:1 case :slightly_smiling_face:

matt.fellows
2021-06-15 06:42
So you?ll need two calls in your case. Two consumers (because of the messages limitation) talking to _n_ providers

matt.fellows
2021-06-15 06:42
If you specificy multiple `--pacticipant` then it will not automatically detect the dependencies: ```#### Alternate usage - specifying dependencies explicitly If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify one or more of the dependencies explictly. You must also do this if you want to use the `--all TAG` option for any of the pacticipants. You can specify as many application versions as you like, and you can even specify multiple versions of the same application (repeat the `--pacticipant` name and supply a different version.) You can use explictly declared dependencies with or without the `--to ENVIRONMENT_TAG`. For example, if you declare two (or more) application versions with no `--to ENVIRONMENT_TAG`, then only the applications you specify will be taken into account when determining if it is safe to deploy.....```


dimundo
2021-06-15 06:44
oh, pardon me :disappointed:

matt.fellows
2021-06-15 06:45
BUT

matt.fellows
2021-06-15 06:45
conflicting docs is bad, I?m just readig what you sent - hold that thought :laughing:

matt.fellows
2021-06-15 06:46
phew, all good - we are consistent. This bit alludes to the bigger problem with specifying dependencies manually

matt.fellows
2021-06-15 06:46
TL;DR - just specify the application you want to deploy, and let the broker work out the rest

lucas.rolle
2021-06-15 06:48
has joined #pact-js

dimundo
2021-06-15 06:48
this is `1:many` case

dimundo
2021-06-15 06:49
still, very usefull for bunch of different api providers :+1: ( in my case )

dimundo
2021-06-15 06:51
`messages`+`api`s creates `many:many` case ( sadly, we are not living in a perfect world )

dimundo
2021-06-15 06:51
but, i?ve got the idea, thank you very much :pray:

matt.fellows
2021-06-15 06:54
Yeah, that?s a problem/limitation with the framework (that?s to be fixed in v4 of the spec, but for now we live in this world)

matt.fellows
2021-06-15 06:54
Perhaps raise a request on http://pact.canny.io?

matt.fellows
2021-06-15 06:54
(and double check if it?s already been requested)

caoilte
2021-06-15 11:36
has joined #pact-js

sreid
2021-06-15 11:46
has joined #pact-js

thanuxxxx
2021-06-15 13:37
``` tipSuggestions: eachLike( { id: like('526BKHDR76G7E'), name: like('Best Service Ever!'), percentage: like(30), }, {min: 4} ),```

thanuxxxx
2021-06-15 13:41
I only see the error when min is greater than 1

thanuxxxx
2021-06-15 13:54
I think that might be a bug because I used to have `PactfileWriteMode` is `update`, after I change to `overwrite` I don't see the error

caoilte
2021-06-15 14:43
@caoilte has left the channel

leonardo.viana
2021-06-15 15:57
I noticed that the `exampleValue` within `fromProviderState` in Pact JS V3 beta is currently defined with a data type of `string`: https://github.com/pact-foundation/pact-js/blob/e0aa360efd7995dc9c5f330fa6f450525e67b54d/src/v3/matchers.ts#L450 However, this prevents us from using non-string data types within TypeScript tests, like a number, similarly to what is being done in this JavaScript example: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/provider-state-injected/consumer/transaction-service.test.js#L45 It seems to me that the data type should be defined as `any`, not `string`, otherwise that greatly limits the data types used for replacements. Is this a bug?

danielabbitt
2021-06-15 17:12
has joined #pact-js

tom.borglum
2021-06-15 17:29
has joined #pact-js

thanuxxxx
2021-06-15 18:15
Any Idea why few of my pact tests fails occasionally `with 30000 ms timeout for Pact` & `Pact verification failed - expected interactions did not match actual.` ?

mathias.duesterhoeft
2021-06-15 19:08
Hi there, I am trying to use pact-js `10.0.0-beta.37` with typescript `4.2.4` - and `tsc --build` in my project gives a lot of those errors: ```node_modules/@pact-foundation/pact/src/messageConsumerPact.d.ts:4:25 - error TS2307: Cannot find module 'common/jsonTypes' or its corresponding type declarations. 4 import { AnyJson } from 'common/jsonTypes'; ~~~~~~~~~~~~~~~~~~ node_modules/@pact-foundation/pact/src/v3/xml/xmlElement.d.ts:1:25 - error TS2307: Cannot find module 'v3/matchers' or its corresponding type declarations. 1 import { Matcher } from 'v3/matchers';``` In `matchers.ts` the import is actually `import { AnyJson, JsonMap } from 'common/jsonTypes';` see https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/dsl/matchers.ts#L7 I am not sure why the absolute path import is not working in my project. But also pact-js seems to be mixing both relative and absolute import. Is this a good idea. Any help is highly appreciated

matt.fellows
2021-06-15 23:26
Thanks for the PR. I think we?ll just do that for consistency.

matt.fellows
2021-06-15 23:26
I can?t recall the intricacies of the TS compilation process, but makes sense to be as ?import? friendly as possible

matt.fellows
2021-06-15 23:30
cc @tjones, I recall a similar situation recently so may have more context

tjones
2021-06-16 00:06
occasional failures are usually because of some kind of promise mishandling. Check your code to make sure that you are correctly passing promises back to jest's `it` etc.

thanuxxxx
2021-06-16 00:07
Yes, there was an issue of promise handling. Thank you

leonardo.viana
2021-06-16 00:48
Just to followup on this. I changed my local pact-js V3 beta installation to use `any` instead of `string` for the `exampleValue` parameter of `fromProviderState` and that gets rid of the TypeScript failure in the consumer side and allows me to define something like: ```.withRequest({ method: 'PUT', path: ..., body: { updated_at: MatchersV3.fromProviderState('${updated_at}', 1623700550085), }, })``` However, the provider tests still fail because it still replaces my `updated_at` variable with a `string` instead of `number` (even though I return a number in `stateHandlers`) and our provider expects that field to be a number. Is there any way to tell pact-js V3 to replace a field value with a `number`, not `string`? Any help is greatly appreciated.

mathias.duesterhoeft
2021-06-16 06:44
Thanks for having a look - the build was failing in the PR - but I am a little bit lost lost there - does not look like the build error is related to my change. `Error: Cannot find module '@pact_foundation_greet/pact'`

michael.branders
2021-06-16 06:57
has joined #pact-js

tjones
2021-06-16 07:27
Yep, completely unrelated. Looks like the branch is broken, I?ll fix that (and I?ve merged your change)

tjones
2021-06-16 07:27
Thanks for the PR!

bethskurrie
2021-06-16 07:35
@tonynguyenit18 just wanted to follow up with you on this fix. Have you found that it's working the way you want it to now?

tjones
2021-06-16 07:56
We?ve just released jest-pact `0.9.1` with support for Jest 27 :tada:

jedlicka
2021-06-16 10:12
has joined #pact-js

leonardo.viana
2021-06-16 11:59
I?m still stuck on this dynamic replacement of a number. @matt.fellows, @tjones, sorry to bother you guys, but do you if it?s possible in Pact JS V3 to do the kind of number replacement I explained above?

matt.fellows
2021-06-16 12:33
:wave:

matt.fellows
2021-06-16 12:33
hmm I?m not sure sorry, it?s a pretty new feature

matt.fellows
2021-06-16 12:36
Ah yes. Sorry for some reason slack collapsed the first half of the conversation

matt.fellows
2021-06-16 12:36
I was just checking that example, and it does what you want

matt.fellows
2021-06-16 12:37
Could you please raise an issue? Easily fixed

matt.fellows
2021-06-16 12:37
for now, you?ll need to TS brute force your way through with a cast

matt.fellows
2021-06-16 12:37
We can do better than an any (because it doesn?t accept an any), but it?s also not limited to strings

leonardo.viana
2021-06-16 12:51
Thanks @matt.fellows. I raised the following issue for this: https://github.com/pact-foundation/pact-js/issues/696

jpasse
2021-06-16 13:45
has joined #pact-js

tonynguyenit18
2021-06-16 14:43
@bethskurrie I?m waiting for the release. Have you release it if yes what version it?s?

jan.malkiewicz
2021-06-16 14:48
has joined #pact-js

akennedy
2021-06-16 21:40
Hey all, I'm having an issue whereby the request path used during the call via the consumer needs to be different than the request path used when calling the provider directly. Specifically, an id needs to be appended when calling the provider directly, but the consumer automatically appends that id, so my consumer contract just has a simple path, e.g. `/forms` Since the consumer contract uses the unappended path, is there any way to some how add this required appended id at a later point? Any other ideas as to how to make this work?

matt.fellows
2021-06-16 22:10
If the consumer automatically appends it, wouldn?t it be in the contract then?

matt.fellows
2021-06-16 22:10
Is the issue you don?t have control over it on the consumer test?

akennedy
2021-06-16 22:49
The resulting contract shows the unappended path `/forms` . When I go to run provider-verify, I get a 500 error response because it's using the path `/forms` with the error that it's missing the appended id. There's something that happens outside of my test in the consumer service that appends the id before the request hits the provider API.

akennedy
2021-06-16 22:50
If the consumer contract could save the appended id I should be set, I just can't set up the interaction beforehand to include the id, it must remain `/forms`

bethskurrie
2021-06-16 22:52
@tonynguyenit18 are you using the OSS broker? It's out in Pactflow SAAS.

tonynguyenit18
2021-06-16 23:22
@bethskurrie Yep I?m using OSS Broker. Do you have plan to release this fix for let OSS Broker users?

matt.fellows
2021-06-16 23:54
I?m just confused as to how your client sends the parameters but you can?t add that to your test?

matt.fellows
2021-06-16 23:54
> here?s something that happens outside of my test in the consumer service like a proxy or something?

akennedy
2021-06-17 00:06
It does it in the function I'm using to make the call: ```async getForms(companyId) { const forms = await this.get(`/forms?company_id=${companyId}`); }``` This is in the consumer repo outside of my test. I then call getForms with a companyId

matt.fellows
2021-06-17 00:19
What does your test do? It should be calling `getForms`

matt.fellows
2021-06-17 00:20
That's the thing that makes the API call so should be the target of your pact unit test

matt.fellows
2021-06-17 00:20
If you're not testing that function you're not testing the real code and your test will get out of sync

akennedy
2021-06-17 00:28
I think the issue this whole time was with my interactions file and not with my test itself. Looking into adding `query:` after `path:`and I think that might do the trick :sweat_smile:. Thanks for the help!

matt.fellows
2021-06-17 00:44
excellent!

matt.fellows
2021-06-17 00:44
glad you worked it out :stuck_out_tongue:

jeen.broekstra
2021-06-17 06:13
has joined #pact-js

minijb225
2021-06-17 06:44
has joined #pact-js

dimundo
2021-06-17 08:05
hi! I have such pact config ``` const messagePact = new MessageConsumerPact({ consumer: "MessageConsumerJSApp", dir: path.resolve(process.cwd(), "pacts"), pactfileWriteMode: "update", provider: "MessageProviderScalaApp", logLevel: "info", })```

dimundo
2021-06-17 08:07
> export declare type PactfileWriteMode = ?overwrite? | ?update? | ?merge?; setting to overwrite/merge makes `Error: thrown: "Could not find command \"merge\".`

dimundo
2021-06-17 08:07
`Error: thrown: "Could not find command \"overwrite\".`

matt.fellows
2021-06-17 08:08
I think I know what it is

matt.fellows
2021-06-17 08:08
for message pact though, just drop it - it doesn?t support that flag

matt.fellows
2021-06-17 08:08
(it always merges)


matt.fellows
2021-06-17 08:08
it should be a different type, and that option shouldn?t be present, basically

dimundo
2021-06-17 08:09
then other question comes - if i rename `expectsToReceive` param, then both interactions are in the pact :disappointed: so one must delete pact before running tests

matt.fellows
2021-06-17 08:12
yes, you must clear out the pacts directory beforehand

matt.fellows
2021-06-17 08:12
If that?s not document, then we must have removed it - apologies if that?s the case

matt.fellows
2021-06-17 08:12
I have to run for dinner etc., but will check in later

dimundo
2021-06-17 08:20
so `"test:consumer": "jest consumer/*-contract.spec.js --env=node",` better to be like `"test:consumer": "rimraf pacts && jest consumer/*-contract.spec.js --env=node",`

matt.fellows
2021-06-17 08:22
Yeah


dimundo
2021-06-17 08:25
but one must remember to run clean, imho inline is better/safer

dimundo
2021-06-17 08:26
sad story about extra dependency :disappointed: could be extra strategy added to pact file (re)creation ?

leonardo.viana
2021-06-17 16:26
I?m having this exact same problem, so I?m glad I found this thread. @matt.fellows, @tjones, is there a GitHub issue that we can use to track the progress on this?


leonardo.viana
2021-06-18 00:03
But, is there an item that tracks this ?state handlers need to wait for promises to resolve? issue specifically?

matt.fellows
2021-06-18 01:00
no

matt.fellows
2021-06-18 01:00
the API itself will be redesigned, so a number of considerations will be there (including ideally support for backwards compatibility with the current stable interface, which supports promises)

matt.fellows
2021-06-18 01:01
I?d like to evolve this discussion into one about the API design: https://github.com/pact-foundation/pact-js/discussions/681

matt.fellows
2021-06-18 05:47
> but one must remember to run clean, imho inline is better/safer Agreed! That was my point above - it?s there, but it should be inline

matt.fellows
2021-06-18 05:48
> sad story about extra dependency :disappointed: could be extra strategy added to pact file (re)creation ? I think we could find a way to support it. Pact message has some challenges that HTTP doesn?t, but if you could please raise a feature request we?ll see what we can do

tomknee1
2021-06-18 08:15
has joined #pact-js

rockin291
2021-06-19 05:18
has joined #pact-js

zainamro1
2021-06-20 17:17
has joined #pact-js

nferrazzano
2021-06-21 05:23
has joined #pact-js

lewis.prescott079
2021-06-21 12:55
has joined #pact-js

github2
2021-06-21 13:10
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.38_ published by github-actions[bot]

tjones
2021-06-21 14:27
@dimundo: For jest-pact, it?s a bit hard, because the test runner doesn?t give the tests much context about how they?re running (they?re quite well isolated). I?d like to export a clean step that you can include in your jest setup, since it allows modules to be used. It would delete your pacts first. However, I?m a bit concerned that it might cause surprise behaviour if people are running only part of their test suite, and I also want to be careful not to delete the wrong thing (which can also be hard in some setups). Suggestions welcome!

github2
2021-06-21 14:35
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v9.16.0_ published by github-actions[bot]


dimundo
2021-06-21 14:40
looks like `clean` step is the way - deterministic result for brave guys ( and gals ) :slightly_smiling_face:

mathias.duesterhoeft
2021-06-21 16:36
Is something broken here - the release artifacts are still missing?

vlad
2021-06-21 18:23
has joined #pact-js

christopher.doherty
2021-06-21 19:01
has joined #pact-js

liorra
2021-06-22 04:17
has joined #pact-js

matt.fellows
2021-06-22 04:22
It looks like there was an issue with the rust build. Some dependency in the chain no longer works with Rust :laughing: . I?ll look at this tomorrow

dimundo
2021-06-22 09:08
Hi anyone seen `command not found: pact-broker` could be due using `yarn` , not `npm` ( and , maybe `pnp` )

stanojevic.boban
2021-06-22 10:20
has joined #pact-js

matt.fellows
2021-06-22 10:34
What are doing when that shows up?

dimundo
2021-06-22 10:49
trying to publish to broker

matt.fellows
2021-06-22 12:41
from the command line or in a JS file?

matt.fellows
2021-06-22 12:41
If you could share the command/code example hat?d be great

matt.fellows
2021-06-22 12:42
I know if you run `npx pact-broker` outside of the directly containing `node_modules` it isn?t supported

miguel.carneiro
2021-06-22 12:51
has joined #pact-js

tjones
2021-06-22 14:16
```npx --package @pact-foundation/pact pact-broker``` :slightly_smiling_face:

tjones
2021-06-22 14:19
@dimundo This usually happens if the binaries weren?t installed. Sometimes that will happen when `npm install` fails and you don?t notice, or if you?re running `npm install --ignore-scripts` (or whatever the yarn equivalents are). Unfortunately, the post-install script isn?t run if the install worked. Try deleting `node_modules/@pact-foundation/pact-node` (or `node_modules/@pact-foundation/pact-core` if you?re on the beta v10) and then rerun `npm install` (or whatever the yarn equivalent is)

tjones
2021-06-22 14:20
If that doesn?t fix your problem, how are you trying to invoke `pact-broker`?

tjones
2021-06-22 14:25
?..we should probably put that in the documentation

dimundo
2021-06-22 14:28
there are no node_modules for yarn

tjones
2021-06-22 14:29
Really? There was last time I used it. I thought it was npm compatible. Where does it download packages?

dimundo
2021-06-22 14:30
some other folder, but probably it is project-related

dimundo
2021-06-22 14:31
workarounded with

dimundo
2021-06-22 14:32
const {Publisher} = require("@pact-foundation/pact") ... new Publisher(opts) .publishPacts()

tjones
2021-06-22 14:34
Ok. I suspect that the postinstall script didn?t run. Google tells me that yarn will respect this, but if you?re using yarn 2, it has a mode called PnP (plug-n-play) that doesn?t have a node_modules location. I can?t easily see what folder you?ll need to clear to get yarn to reinstall the package

dimundo
2021-06-22 14:34
yep, pnp

dimundo
2021-06-22 14:34
`plug-and-pray`

dimundo
2021-06-22 14:35
but it worked from code, which is even better at some point

tjones
2021-06-22 14:35
The page about why they changed it is not super helpful

tjones
2021-06-22 14:39
Sooo it looks like pnp keeps the packages as zips and unpacks them at runtime. But the page about the lifecycle scripts that they support suggests that it will unpack the zip if there is a lifecycle script:

tjones
2021-06-22 14:40
> postinstall is called after a package got successfully installed on the disk. It is guaranteed. and > Postinstall scripts have very real consequences for your users. In most cases Yarn will keep the installed packages in its cache under their archive form, and will instruct Node to load the files directly from there. This leads to much smaller installs, and eventually to Zero-Installs. > Unfortunately postinstall scripts break this model because they signal Yarn that those packages may need to mutate their own directory, forcing them to be extracted into physical locations on the disk and leading to heavier, slower, and less stable installs.

tjones
2021-06-22 14:41
(I find the yarn documentation to mostly be written in terms of complaints about npm, which has always turned me off the project. Yes, this is me complaining about complaints :joy:)

tjones
2021-06-22 14:41
There are also a number of packages listed as incompatible with pnp: https://yarnpkg.com/features/pnp#incompatible

tjones
2021-06-22 14:42
It?s possible that pact should also be on that list? I don?t know what it is about those projects that make them incompatible

tjones
2021-06-22 14:43
Flicking through some of those linked issues, those all look like things we don?t do, though. Hmmm

tjones
2021-06-22 14:43
haha!

tjones
2021-06-22 14:44
Do you get errors on a `yarn install` on a fresh checkout? Do you get the logging output from the download?

tjones
2021-06-22 14:44
We really should just package the download with the dependencies in it

tjones
2021-06-22 14:47
Yarn?s pnp says that it does this: > When using PnP, packages are stored and accessed directly inside the Zip archives from the cache. The PnP runtime (.pnp.cjs) automatically patches Node?s fs module to add support for accessing files inside Zip archives. This way, you don?t have to do anything special: I wonder if that?s a problem if we?re `spawn`ing rather than using `require` or `fs`

tjones
2021-06-22 14:48
Looks like you can turn it off and use `node_modules` - I?d be curious if that solves your issue

tjones
2021-06-22 14:49
they have a list of packages that had to update in order to support this, a list of packages that don?t work at all with pnp, and then they go on to warn you that using node_modules might not work :confused: https://github.com/yarnpkg/berry/tree/master/packages/plugin-node-modules Powerful and innovative indeed :joy:

tjones
2021-06-22 14:50
Also try running the verifier with `logLevel: 'DEBUG'` - it should tell you what command it is trying to run

dimundo
2021-06-22 14:50
>Looks like you can turn it off and use node_modules not sure if our js guys will allow such changes

tjones
2021-06-22 14:54
just trying to build one of my projects with yarn 2, but it?s not in homebrew

tjones
2021-06-22 14:55
oh, I see. You have to explicitly enable it. Is it still experimental?

dimundo
2021-06-22 14:56
nope, moved from demo to poc stage

dimundo
2021-06-22 14:57
so far consumer is working, next step - scala

dimundo
2021-06-22 14:57
and then fine-tuning

tjones
2021-06-22 14:57
Sorry, I meant, is yarn 2 still experimental?

dimundo
2021-06-22 14:58
ah, yes , for some year at least iirc

tjones
2021-06-22 14:59
Ok, I?m unable to run my pact tests with yarn 2 (for a different reason).

tjones
2021-06-22 15:00
My feeling is that yarn is broken rather than pact is broken, but I?m happy to be persuaded otherwise

tjones
2021-06-22 15:01
``` pino tried to access pino-pretty, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. Required package: pino-pretty (via "pino-pretty") Required by: pino@npm:6.11.3 (via /Users/work/office/temp/remember/.yarn/cache/pino-npm-6.11.3-63b6174ef5-c6fa52d31b.zip/node_modules/pino/lib/)``` ^ This is the logging library that pact uses

dimundo
2021-06-22 15:01
yeah ,also this

tjones
2021-06-22 15:02
That?s the latest version.

tjones
2021-06-22 15:03
My feeling is that yarn?s approach sounds nice in theory, but it fixes problems that I?ve never run into and causes problems that we are now running into.

tjones
2021-06-22 15:04
Let us know if there?s anything we can do to help

tjones
2021-06-22 15:04
I think this is a bug with yarn

tjones
2021-06-22 15:04
from the position they take in the docs, yarn will think it?s a bug with pino

tjones
2021-06-22 15:05
I want pact not to care how you install it

tjones
2021-06-22 15:05
so if there?s something we can do differently to get you going with yarn 2, I?m keen to do it

tjones
2021-06-22 15:08
hmmm. Even though I can?t run the tests, the binary is there: ``` ls .yarn/unplugged/\@pact-foundation-pact-node-npm-10.12.2-cc2bb34b6a/node_modules/\@pact-foundation/pact-node/standalone/darwin-1.88.49/pact/bin/ pact* pact-broker* pact-message* pact-mock-service* pact-provider-verifier* pact-stub-service*```

tjones
2021-06-22 15:09
(see if you have a folder like that)

tjones
2021-06-22 15:13
I just checked our source - we download and check for the binaries relative to the path of the pact-node folder, so we shouldn?t get errors like you?re getting even with pnp. However, I didn?t see the logs from the postinstall script, so it?s possible that if the postinstall fails (eg for firewall or other issues), then yarn is suppressing them?

tjones
2021-06-22 15:14
aaand I can?t run the tests because of the `pino` issue

tjones
2021-06-22 15:16
how did you make yarn get past the `pino` issue? it?s bedtime here, but I?ll check back tomorrow

dimundo
2021-06-22 15:56
we are starting to celebrate here our ~pagan~ ancient https://en.wikipedia.org/wiki/J%C4%81%C5%86i :smile: so we are off till monday :slightly_smiling_face: but i will appear occasionally

srinagasai.krishnasan
2021-06-22 17:35
has joined #pact-js

matt.fellows
2021-06-23 02:31
Looking at this today Mathias

varnit.garg2424
2021-06-23 06:19
has joined #pact-js

tjones
2021-06-23 06:41
So, I tried with that .yarnrc patch, but unfortunately I can?t build my project because I?m using absolute imports + typescript, which yarn?s pnp mode doesn?t respect.

tjones
2021-06-23 06:45
I?m not keen to spend much more time trying to get yarn 2 to build projects that are otherwise configured correctly. If you suspect that pact is the issue, is it possible for you to share a repository where we can reproduce the problem?

tjones
2021-06-23 06:47
Also I hope you are having an excellent J??i, thanks for the interesting link!

dimundo
2021-06-23 06:59
i think pact is ok, this is just another yarn magic (as far tests are created) :)

github2
2021-06-23 07:43
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.39_ published by github-actions[bot]

matt.fellows
2021-06-23 07:58
New release out, artifacts are attaching this time :stuck_out_tongue:


matt.fellows
2021-06-23 07:58
NPM was done for the first release :man-shrugging:

matt.fellows
2021-06-23 07:58
hopefully that all went out nicely!

varun.patil
2021-06-23 12:44
has joined #pact-js

achuljyan
2021-06-23 21:17
has joined #pact-js

sagupta
2021-06-23 21:56
Hello Team, I am facing a error during provider verification step. I have tested the response from API locally in Postman and i am getting the response in `json` format. however when i run the pact provider tests and check the logs , I notice that the response from API as per logs is in `html` format and hence the tests are failing and i get errors for body verification and header verification ``` Failure/Error: expect(header_value).to match_header(name, expected_header_value) Expected header "Content-Type" to equal "application/json; charset=utf-8", but was "text/html; charset=UTF-8" # ./bin/pact:15:in `<top (required)>'``` in the contract , I have mentioned the header `Content-type: application/json; charset=utf-8` in. both request body and response body. Still API is returning in html . Has anyone faced this error and was able to fix it?

sagupta
2021-06-23 22:35
Fixed it , I was missing some hidden headers which postman was adding and when i added those too to the contract , it worked

bethskurrie
2021-06-23 23:23
@tonynguyenit18 yes, there are just a few outstanding things I need to do before I can release it. Sorry - I've had less than my normal amount of time on OSS recently.

mselvakumar
2021-06-23 23:54
has joined #pact-js

srikanth.rachakonda
2021-06-24 02:32
has joined #pact-js

github2
2021-06-24 03:54
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.40_ published by github-actions[bot]

ali.akbar
2021-06-24 06:58
has joined #pact-js

ali.akbar
2021-06-24 07:37
Hello everyone! I'm writing contract based tests with pact-js and jest but I'm seeing an error while following https://www.mariedrake.com/post/contract-testing-with-pact-js-and-jest: ```TypeError: Cannot read property 'verify' of undefined afterEach(() => provider.verify()); ^``` It's all happening bcz of `jsdom` test environment. By default Jest uses `jsdom` to mimic a real browser environment (RBE) in tests. Changing this to `node` may solve the issue here but the `setupTest.js` is using RBE supported code (something like `window.getComputedStyle = jest.fn(() => ({})`) which doesn't work in when you set test environment to `node` and shows the following error: ``` The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/en/configuration#testenvironment-string. Consider using the "jsdom" test environment. ReferenceError: window is not defined 33 | } 34 | > 35 | window.getComputedStyle = jest.fn(() => ({ | ^``` As shown above, the unit tests are written following `jsdom` here so changing the `setupTest.js` may not be possible in my case. More details written in the https://github.com/pact-foundation/pact-js#usage-with-jest of pact-js (also links to https://github.com/pact-foundation/pact-js/issues/10). Does anyone know how can we use `provider.verify()` without changing the Test Environment of jest?

tjones
2021-06-24 08:02
I don?t remember why `jsdom` doesn?t work with Pact, but I think it?s not something we can easily work around - (I?m interested to look into it, as it would solve some problems for angular users). One pattern that?s an easy workaround is to have a separate jest setup for pact, and to run your pact tests separately (eg by naming them `*.spec.pact.ts` or similar)

tjones
2021-06-24 08:03
Pact needs to be able to spin up binaries and in some cases servers, which might be the problem with jsdom

tjones
2021-06-24 08:05
Although, I?m wondering if something else is going on - looking at that example, it should be failing in the `beforeEach` not the `afterEach` if there?s a problem spinning up the mock server.

ali.akbar
2021-06-24 08:26
Yes, strange enough that the test I wrote actually passed. I get a proper and expected response from the mocked server and even the provider is valid during the execution of test (console.log-ed the pact provider object).

tjones
2021-06-24 09:08
So you?re saying it does work?

tjones
2021-06-24 09:11
I?m very confused about how the provider object could be undefined later. I suspect something else is going on.

ali.akbar
2021-06-24 09:14
yes exactly! the test run as expected and I can access provider inside the tests but whenever we try to call `provider.verify()`or `provider.finalize()` this error occurs.

tjones
2021-06-24 09:15
can you share your whole test code?

tjones
2021-06-24 09:15
where is the error coming from?

tjones
2021-06-24 09:15
(as in, is it in your tests, or in something like `jest-pact`, which also contains that line)

tjones
2021-06-24 09:15
are there other errors too?

ali.akbar
2021-06-24 09:37
I had to remove some of the confidential code here: ```const provider = new Pact({ consumer: 'consumer', provider: 'provider', port: 3999, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'INFO', }); const { somethingLike: like } = Pact; describe('*** Service', () => { describe('When a request *** is made', () => { beforeAll(async () => { provider.setup() }); it('should return the correct data', async () => { console.log(provider); const response = await getSomething('some-id'); expect(response).toBeTruthy(); }); afterEach(() => provider.verify()); afterAll(() => provider.finalize()); });``` Running this using `npm test` and it gives me the following errors in terminal: ```console.log Pact { opts: { consumer: 'consumer', cors: false, dir: '***/pacts', host: '127.0.0.1', log: '***/logs/pact.log', logLevel: 'INFO', pactfileWriteMode: 'overwrite', provider: 'provider', spec: 2, ssl: false, port: 3999 }, server: Server { _events: [Object: null prototype] { delete: [Function] }, _eventsCount: 1, _maxListeners: undefined, options: { consumer: 'consumer', cors: false, dir: '***/pacts', host: '127.0.0.1', log: '***/logs/pact.log', pactFileWriteMode: 'overwrite', port: 3999, provider: 'provider', spec: 2, ssl: false, sslcert: undefined, sslkey: undefined }, __running: false, __cliVerb: { cliVerb: 'service' }, __serviceCommand: 'standalone/darwin-1.88.49/pact/bin/pact-mock-service', __argMapping: { port: '--port', host: '--host', log: '--log', ssl: '--ssl', sslcert: '--sslcert', sslkey: '--sslkey', cors: '--cors', dir: '--pact_dir', spec: '--pact_specification_version', pactFileWriteMode: '--pact-file-write-mode', consumer: '--consumer', provider: '--provider', monkeypatch: '--monkeypatch', logLevel: '--log-level' }, [Symbol(kCapture)]: false } } at _callee2$ (src/pact-tests/***.test.jsx:82:15) FAIL src/pact-tests/***.test.jsx (7.43 s) *** Service When a request for *** is made ? should return the correct data (79 ms) ? *** Service ? When a request for *** is made ? should return the correct data TypeError: Cannot read property 'verify' of undefined 84 | expect(response).toBeTruthy(); 85 | }); > 86 | afterEach(() => provider.verify()); | ^ 87 | afterAll(() => provider.finalize()); 88 | }); 89 | at Pact.verify (node_modules/@pact-foundation/src/httpPact.ts:116:8) at Object.<anonymous> (src/pact-tests/***.test.jsx:86:30) ? *** Service ? When a request for *** is made ? should return the correct data Port 3999 is unavailable on address 127.0.0.1 at Server.<anonymous> (node_modules/@pact-foundation/src/common/net.ts:44:18)```

abubics
2021-06-24 10:47
If you're creating your own `const provider` at the top like that, I don't see how it could become undefined in a lower scope / execution context. I've had some lifecycle issues with a provider being undefined outside of `before*` / `after*` functions in jest-pact, but that sounds unrelated (opposite symptom, and different configuration).

tjones
2021-06-24 11:34
``` at Pact.verify (node_modules/@pact-foundation/src/httpPact.ts:116:8)``` ^ I think this is a key symptom. It indicates that the server hasn?t started yet

ali.akbar
2021-06-24 11:35
isn't provider.setup starting the server here?

tjones
2021-06-24 11:37
it should be, but perhaps it is failing. Can you try running with `logLevel: debug`?

tjones
2021-06-24 11:37
Also, is there any other failure output? Sometimes Jest repeats the thrown exceptions at the end of the test run, but there are other errors further up.

tjones
2021-06-24 11:38
oh, this is the problem: ``` beforeAll(async () => { provider.setup() });```

tjones
2021-06-24 11:39
`provider.setup()` is a promise, but you?re not `await`ing it

tjones
2021-06-24 11:40
As an aside, I recommend making `async` without `await` a lint error. The following eslint rule does that: https://eslint.org/docs/rules/require-await

tjones
2021-06-24 11:41
if you check the example you linked, the promise is returned: ``` beforeAll(() => // note no { provider.setup()```

tjones
2021-06-24 11:42
Also, if you upgrade to `9.16.0`. you?ll get a nicer error message than the `undefined` type error you are currently getting

ali.akbar
2021-06-24 11:43
Oh, I already use `.then()` with this. (I removed it bcz I added an interactions which I removed due to confidentiality)

tjones
2021-06-24 11:44
Yes, but you?re not returning the promise

ali.akbar
2021-06-24 11:44
Do I still have to use await if I'm using `setup().then()`?

tjones
2021-06-24 11:45
``` beforeAll( async () => { somePromise } ) // This does not wait for the promise beforeAll(() => somePromise ) // this does, because it is implicitly returning the promise beforeAll( async () => { await somePromise } ) // This does, because it is awaiting```

tjones
2021-06-24 11:46
Yes. You either need to remove the `{` and `}`, (and you can then remove `async`) or you need to add `await`

tjones
2021-06-24 11:46
`.then()` doesn?t do anything other than turn one promise into another

tjones
2021-06-24 11:49
You need to wait for the `provider.setup()` promise to complete before you can use the provider. Jest will wait on any promises that are returned from `beforeAll` before moving on. This is why all the pact example return promises (and also why the example in the blog you linked returns the promise in the `beforeAll`). `await` is just syntax that makes the function return a promise. It lets you write promises in a procedural way (personally I prefer not to use this style)

tjones
2021-06-24 11:49
There?s nothing magic happening with promises unless you use `await`

ali.akbar
2021-06-24 11:50
I'm using await now and it's still giving me the same error.

tjones
2021-06-24 11:50
can you share the code?


tjones
2021-06-24 11:54
Sorry, I mean: ``` beforeAll(async () => { provider.setup() });``` ^ This definitely won?t work ``` beforeAll(async () => { await provider.setup() });``` ^ This should work

tjones
2021-06-24 11:55
So I was interested to confirm what the code looked like after changes

ali.akbar
2021-06-24 11:55
I did the later as you said: ``` beforeAll(async () => { await provider.setup() });```

tjones
2021-06-24 11:58
Hmm, ok. The next step is to add `logLevel: "DEBUG"` and see what the log says

tjones
2021-06-24 11:58
(to `new Pact()` at the top)

ali.akbar
2021-06-24 12:12
Oh, I was using a port which was already in use but you were right, I was missing an `await` here. Didn't know it was a promise before. I can finally make a provider server. :raised_hands: Thanks a lot for such quick responses. I'll let you know if I have any questions.

abubics
2021-06-24 12:12
guess that explains the `Port 3999 is unavailable on address 127.0.0.1` :sweat_smile:

abubics
2021-06-24 12:13
:taco: for @tjones late-night help :3

leonardo.viana
2021-06-24 12:56
Hi team. When successful, our PUT requests return a status of 200 with no body, and when it fails it returns a non-200 status (e.g. 400) and a JSON body with a description of the error (this is standard practice in the industry). Since we want to make sure that the response contains both, the 200 status as well as the null body, we defined the following in the consumer test: ``` .willRespondWith({ status: 200, body: null });``` However, it turns out that if we put a body with a `null` value like that it will simply be left out of the pact contract, so the provider test never actually validates the body and we get the following results: ``` returns a response which has status code 200 (FAILED) has a matching body (OK)``` Now, I can manually add a body with a value of `null` in the contract JSON file, and if I do that things are slightly better because now the provider test knows that the body did not match: ``` returns a response which has status code 200 (FAILED) has a matching body (FAILED) 1.1) has a matching body / -> Expected empty body but received Present(140 bytes, application/json;charset=utf-8) 1.2) has status code 200 expected 200 but was 400``` Unfortunately, however, the output never displays the actual value of the body, which contains the JSON error message that?s extremely helpful in debugging. In other words, what we really want is an output that contains the actual response body, like: ``` 1.1) has a matching body / -> Expected empty body but received {"error":"validation","reason":"invalid input format","details":"invalid type specified for updated_at"}``` We are using the latest Pact JS V3 beta.40: is it possible to do what I describe above, and if not should I file an issue for this?

leonardo.viana
2021-06-24 13:08
BTW, I also tried defining a response body with an empty map `{}` but in beta.39/40 the provider test still thinks that the body matches (even though it doesn?t): ``` returns a response which has status code 200 (FAILED) has a matching body (OK)``` However, using an empty map `{}` in beta.37 seemed to indeed display the JSON body in the output, so I?m wondering why that was removed in more recent versions: ```1.1) has a matching body / -> Expected empty body but received {"error":"validation","reason":"invalid input format","details":"invalid type specified for updated_at"}``` The only thing I?m not sure about yet, is whether having an empty map `{}` will also make the provider test pass in the successful case (I haven?t been able to test a successful PUT request yet due to other blocking issues).

tjones
2021-06-24 14:36
I?m just heading to bed here, but my initial reaction is that the correct response for success with no content is 204 (no content)

tjones
2021-06-24 14:37
Also in pact-js, if you have no body, I think you just leave `body` out of the interaction

tjones
2021-06-24 14:39
PUT is defined to require a body when the response code is 200, see: https://datatracker.ietf.org/doc/html/rfc7231#section-6.3.1

tjones
2021-06-24 14:59
By the way, @ali.akbar, we also have `jest-pact`, which is a jest-specific wrapper that sets all the options and hooks for you: https://github.com/pact-foundation/jest-pact

leonardo.viana
2021-06-24 16:30
I played with this some more, and rather than using `null` or `{}`, the empty body should really be represented with `""`. If you do that almost everything works: the consumer test works and generates a pact with the body set to `""`, the provider test fails (as expected) with a body mismatch, and it even prints the actual body length in the error message: ``` returns a response which has status code 200 (FAILED) has a matching body (FAILED) 1.1) has a matching body / -> Expected empty body but received Present(140 bytes, application/json;charset=utf-8)``` The only thing missing is that the actual body content is not also printed. In failed requests like this, the body content normally contains an error message describing exactly what went wrong, so it?s very useful for debugging the problem. Would it be possible to also print the actual body content in the error message above?

ali.akbar
2021-06-24 17:28
ohhh interesting. I saw it somewhere before but I had some doubts. I'll definitely look at it.

erterpstra
2021-06-24 19:20
has joined #pact-js

tjones
2021-06-25 01:13
I'm sure that can be achieved. Is this with the beta branch or the main release?

tjones
2021-06-25 01:14
Also, note that the consumer pact should be only describing the request that you require. Does your implementation really require an empty body?

tjones
2021-06-25 01:15
> Is this with the beta branch or the main release? I ask because pact-js doesn't produce that error message, it delegates to a different pact core depending on which version you're using.

leonardo.viana
2021-06-25 01:19
This is with the latest pact-js v3 beta.40.

matt.fellows
2021-06-25 02:06
thanks for raising Leonardo

matt.fellows
2021-06-25 02:06
It feels like there are two things here: 1. Improvement to the output reporting (to understand / debug) 2. Update the consumer test

matt.fellows
2021-06-25 02:07
I?m with Tim. If your consumer code doesn?t care if there is/is-not a body for the `200` use case _it should not put an expectation in the contract at all_

matt.fellows
2021-06-25 02:07
Otherwise, if the provider decides later on to put a body there, it will break your contract despite your code not actually caring about it

matt.fellows
2021-06-25 02:08
Put another way, your consumer tests should only put in things it needs, not things it doesn?t need

matt.fellows
2021-06-25 02:09
in your case, it?s not important for there to be a body. So just omit it altogether and be indifferent to any response

abinzahid
2021-06-25 06:12
has joined #pact-js

leonardo.viana
2021-06-25 15:49
@matt.fellows, @tjones, there?s one last thing I want to be clear about here because I think it?s a regression. Up until `beta.37`, if you had a pact that expected an empty map `{}` as the body of the response, but you actually ended up getting something different, the provider test would correctly flag that saying that there was a body mismatch and print the actual response body that was received: ``` returns a response which has status code 200 (FAILED) has a matching body (FAILED) 1.1) has a matching body $ -> Expected an empty Map but received {"details":"Threats policy rules updated_at: invalid type specified \"1623765384870\"","error":"validation","reason":"invalid input format"} 1.2) has status code 200 expected 200 but was 400``` However, starting on the very next version of pact-js v3 beta, which is `beta.39` (given `beta.38` is broken), it no longer flags the body mismatch and simply thinks that the body actually matched: ``` returns a response which has status code 200 (FAILED) has a matching body (OK)``` This seems like a regression that needs to be fixed. Let me know if you?d like me to file an issue for this.

tjones
2021-06-25 16:03
Hmm. I?m not across the changes in the binary between those versions, but this reads more to me like a bug that was fixed- pact interactions definite the minimal expected response that the client needs, not (necessarily) the full response. In a consumer test, you specify the fields that your consumer relies on. The response from the provider can have other fields, but the test only checks for the existence of the fields your consumer requires. If your test specifies an empty json body, then any valid json should pass.

tjones
2021-06-25 16:05
If for some reason your client implementation requires that there be no body at all, then I recommend http 204 as linked above

david.vancouvering
2021-06-26 02:49
Hey. I'm using v3 of pact-js (is that a good idea?) Anyway, I have two tests, and in each test as part of the test itself I set up the provider interaction and then run the test. Both tests call the same endpoint with different query parameter. It looks like Pact is failing the second test because the parameter doesn't match the interaction I defined for the *other* test. Am I correct in understanding that you can't have two interactions to the same endpoint that vary in the value of the query param? If so, how do I go about testing this - the query param controls what response I get back...

uglyog
2021-06-26 03:19
You can, but the interactions need to be defined in separate tests and you must provide a different description for each (the parameter to expectsToReceive)

jchandorkar
2021-06-26 09:01
has joined #pact-js

github2
2021-06-26 13:25
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.41_ published by github-actions[bot]

leonardo.viana
2021-06-26 14:26
@matt.fellows, my stateHandlers no longer work on `beta.41`. I get the following error: ```[2021-06-26 14:19:36.408 +0000] INFO (8851 on C02CG10YMD6W): pact@10.0.0-beta.41: debug request/response logging enabled [2021-06-26 14:19:36.436 +0000] DEBUG (8851 on C02CG10YMD6W): pact@10.0.0-beta.41: incoming request body: { "action": "setup", "params": {}, "state": "is authenticated" } headers: { "content-type": "application/json", "accept": "*/*", "host": "localhost:54464", "content-length": "57" } method: "POST" path: "/_pactSetup" RUNS libs/api-client/src/lib/pnr-policy-pact.spec.ts FAIL libs/api-client/src/lib/pnr-policy-pact.spec.ts (6.521 s) for 'is authenticated' has failed - MismatchResult::Error("Invalid response: error sending request for url (http://localhost:54464/_pactSetup): operation timed out", None)``` My stateHandlers look like this: ``` stateHandlers: { 'is authenticated': () => { token = defaultToken; Promise.resolve(`Valid bearer token generated`) },``` I also tried the following variation, but the end result was the same: ``` stateHandlers: { "is authenticated": { setup: () => { token = defaultToken; return Promise.resolve(`Valid bearer token generated`) } },``` Am I missing something?

matt.fellows
2021-06-26 23:16
Hmm I'll have a look today. The examples definitely test this scenario as do tests

matt.fellows
2021-06-26 23:16
In the first example you're not returning a promise, but the second you do so it should work

leonardo.viana
2021-06-26 23:22
The first one is exactly the same code that used to work up until beta.39. Then I installed beta.40 and it stopped working. So I tried the second way but it also failed with the same error.

matt.fellows
2021-06-26 23:33
Thanks. I'll look today. We made a breaking change in this release to the handlers, as we're still evolving the API into what we'd like it to look like in stable.

matt.fellows
2021-06-26 23:34
Apologies, there will be a few more as we stabilise it (the release notes hopefully clarify this)

matt.fellows
2021-06-26 23:34
But I'll fix/get to the bottom of that bug

matt.fellows
2021-06-27 00:06
I?ve just had 5 minutes, and installed the beta 41 release into the e2e project in pact-js


matt.fellows
2021-06-27 00:07
`cd examples/v3/e2e`

matt.fellows
2021-06-27 00:08
```npm i @pact-foundation/pact@beta npm run test:provider```

matt.fellows
2021-06-27 00:08
There should be 4 pending failures, but the others should work

leonardo.viana
2021-06-27 00:42
Edit for my previous message: it used to work up until beta.40 and stopped working on beta.41. Now, I?m still stuck on this. What exactly does this error mean? ```FAIL libs/api-client/src/lib/pnr-policy-pact.spec.ts (8.557 s) for 'is authenticated' has failed - MismatchResult::Error("Invalid response: error sending request for url (http://localhost:51737/_pactSetup): operation timed out", None)```

matt.fellows
2021-06-27 01:04
That tells me the state handler is not worknig correctly. As mentioned, we changed the implementation for PR #702 to introduce a proxy layer (as per the current main / stable) to allow native JS promises

matt.fellows
2021-06-27 01:04
but obviously not working for you

matt.fellows
2021-06-27 01:04
are you able to share your code?

matt.fellows
2021-06-27 01:11
I?ll see about making the error there clearer - basically, the `/_pactSetup` route is dynamically added by Pact JS. I think Tim raised an issue about clarifying what this does and why it exists, and more importantly, how to debug it

rani.sathya
2021-06-27 04:14
has joined #pact-js

leonardo.viana
2021-06-27 17:17
Just to update on this? I found the issue. Not only did the `stateHandlers` change, but also `requestFilter` has a new signature and requires you to call next at the end. My provider tests started working again after I updated it to: ``` requestFilter: (req, _, next) => { req.headers['authorization'] = `${token}`; next(); },```

matt.fellows
2021-06-27 23:42
Ah, my apologies, I didn?t add that to the release notes - so sorry

matt.fellows
2021-06-27 23:42
I updated the documentation for it though if that?s a concilation :stuck_out_tongue:

matt.fellows
2021-06-27 23:42
(but they also now support promises!)

leonardo.viana
2021-06-27 23:44
Yup, we needed the promises support within stateHandlers and I can confirm that they now work. :wink: The last blocker for us now is just https://github.com/pact-foundation/pact-reference/issues/116, so hopefully that will get fixed soon too. :wink:

matt.fellows
2021-06-27 23:45
yep, please follow that issue and we?ll keep you updated!

david.vancouvering
2021-06-28 02:51
Ah, thank you! That was my mistake

cala.dev_pact
2021-06-28 04:07
has joined #pact-js

robert.rap
2021-06-28 06:34
has joined #pact-js

v-ratngupta
2021-06-28 07:13
has joined #pact-js

e.hallowell
2021-06-28 13:28
has joined #pact-js

david.vancouvering
2021-06-28 17:55
Hey, so I found out the problem was an error in my test. But now I have a new problem. I have two tests in two different `describe` blocks, but both using the same provider. In each test, I set up a different interaction with a different `uponReceiving`. Note I am using `@pact-foundation/pact/v3` What happens, if I run both tests, the second one fails because the mock service didn't get the interaction I set up in the first test. If I run each test separately, both pass. Here is the error: ```The following request was expected but not received: Method: GET Path: /experience/listing_details/v2/module_provider Query String: itemId=100750056032&modules=VLS&shippingServiceCode=abc&variationId=abc&vero=false Headers: Accept: text/event-stream``` Do I need to set up a different *provider* for each test? Thanks!

david.vancouvering
2021-06-28 18:25
Well, I created a new provider for each `describe` and that did the trick...

matt.fellows
2021-06-28 23:18
Thanks David - that?s how the examples do them today. @tjones this would be nice to fix in the interface. It should be doable (it just needs a way to reset itself after `executeTest` I think)

david.vancouvering
2021-06-28 23:19
Thanks, I should have looked at the examples more closely

matt.fellows
2021-06-28 23:19
all good, we?ll ideally fix this so you don?t have to

david.vancouvering
2021-06-28 23:20
:thumbsup:


matt.fellows
2021-06-28 23:37
I think that?s all that is needed

david.vancouvering
2021-06-28 23:37
Sounds great. It's not the end of the world to create a new provider...

matt.fellows
2021-06-28 23:39
anything that makes tests more readable though is welcome from my perspective

matt.fellows
2021-06-28 23:39
you can definitely still create multiple, which will allow you to run tests in parallel, if that?s your thing!

matt.fellows
2021-06-29 02:51
@david.vancouvering minor release going out shortly that will allow you to re-use the `PactV3` instance between tests

matt.fellows
2021-06-29 02:51
thanks for reporting

github2
2021-06-29 03:03
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.42_ published by github-actions[bot]

mishalalexander20
2021-06-29 07:36
has joined #pact-js

mishalalexander20
2021-06-29 07:40
Hey guys, glad to be here. I just have two queries - #1 I am an automation test engineer. I have worked with both APIs and UI. But still I am finding it hard to understand the concepts of contract testing. I have followed several tutorials. The way I understand it is - in contract testing using pact, we are testing both the request and response format using mocks at the same time so that we don't have to do end to end testing. Is this a correct understanding? #2 Does it makes sense of an automation test engineer like myself to pick up contract testing?

dimundo
2021-06-29 07:48
i?m a qa, and i introduced pact to my company, so why not

dimundo
2021-06-29 07:48
as for e2e - you still need to have some happy path e2e

dimundo
2021-06-29 07:49
as there are 100500 other points of failure

mishalalexander20
2021-06-29 07:49
so with contract testing, only happy path e2e is required?

dimundo
2021-06-29 07:49
not only with contract

dimundo
2021-06-29 07:50
there must be also unit and integration tests in place

dimundo
2021-06-29 07:50
testing pyramid , you know :wink:

mishalalexander20
2021-06-29 07:50
lol alright. so basically contract testing is more or less act as integration tests for APIs?

mishalalexander20
2021-06-29 07:51
currently we have unit and e2e tests

dimundo
2021-06-29 07:53
> more or less act as integration tests for APIs? i would say no. with pact you cover only format, but content must be covered in other places, as pact is not for full coverage of all cases

mishalalexander20
2021-06-29 07:54
okay got it. thanks Dmitry.


matt.fellows
2021-06-29 07:55
You can, just know that Pact is a white box testing tool - so you need access to the code base

matt.fellows
2021-06-29 07:56
Yes. Pact doesn?t test functional behaviour, just the contract itself. That link Dmitry shared is :mwah:

matt.fellows
2021-06-29 07:57
see also (if you have the demo pack where those slides came from) the slides on how to remove e2e tests, or our videos

mishalalexander20
2021-06-29 07:57
this makes so much sense.


lukemufc125
2021-06-29 07:57
has joined #pact-js

mishalalexander20
2021-06-29 07:58
I got it. With contract testing, you can reduce the number of tests overall including the ones that you put in on the CI/CD pipeline

mishalalexander20
2021-06-29 07:59
rather than testing individual failure cases, you just test the underlying format or contract for each of those.

mishalalexander20
2021-06-29 08:01
thanks guys Dmitry and Matt; I will work with these and come back.

tjones
2021-06-29 08:18
Yes. This is right. You also have less brittle tests, and clearer feedback about what is wrong when it goes wrong

tjones
2021-06-29 08:18
it?s easier to cover all of the API that you?re actually using (which can be hard in e2e)

tjones
2021-06-29 08:19
for me, I consider contract tests to be unit tests but across the API boundary (because the ?unit? includes the consumer and the provider)

tjones
2021-06-29 08:19
that model means I do ?more? unit tests, and ?fewer? integration tests

tjones
2021-06-29 08:21
> so with contract testing, only happy path e2e is required? We recommend testing every type of response that your consumer needs to understand. Does the consumer code have different behaviour in a 401 vs a 404? Then it?s good to cover both with contract tests. Does it do the same thing for every 4XX? Then just pick one and cover that.

tjones
2021-06-29 08:22
The link that @dimundo shared is spot on (:taco:). I would also add: I think it?s good to have functional _coverage_. As in, the contract tests don?t exist to exercise the functionality, but if they happen to do so in the course of running, that is a happy side effect.

mishalalexander20
2021-06-29 08:23
I am very much interesting in contract testing now. I am getting a better understanding now compared to before. But say, if I am starting today, can you tell me on an average how long will it take me to master contract testing? Given that I have worked with testing tools such as Jest, Supertest, mocha, chai, etc.

mishalalexander20
2021-06-29 08:23
and pretty good at JS as well

tjones
2021-06-29 08:24
You can write useful, valuable tests in a matter of a few hours. To master, I don?t know. I feel like I?m still mastering contract testing.

tjones
2021-06-29 08:24
(and testing in general)

tjones
2021-06-29 08:25
if you?ve used jest and supertest you?ll be well ahead. One of our intros starts off by migrating a supertest mock to pact

tjones
2021-06-29 08:25
let me find it for you

tjones
2021-06-29 08:25
Ah, I misremembered. It?s using `nock`: https://github.com/pact-foundation/pact-workshop-js

tjones
2021-06-29 08:26
The problem with `nock`, `supertest`, `restassured` etc is that you aren?t sharing the mock with anyone. With a mock that you can?t share with the provider you are (as @matt.fellows puts it) ?marking your own exam?.

tjones
2021-06-29 08:27
Most companies doing APIs at scale without contract tests have a postman collection that essentially does the same thing but manually.

mishalalexander20
2021-06-29 08:27
true that

tjones
2021-06-29 08:28
I have a dream to write a postman -> pact adapter (and a pact -> postman)

tjones
2021-06-29 08:28
there?s only so much time in the day

mishalalexander20
2021-06-29 08:28
that would be phenomenal! not kidding!

mishalalexander20
2021-06-29 08:28
I understand

mishalalexander20
2021-06-29 08:29
and thanks a lot for sharing Timothy. The workshop is just perfect for me to work on. Thanks again!

dimundo
2021-06-29 08:29
https://insomnia.rest/ is better postman ( as not asking for registration )

tjones
2021-06-29 08:31
I?ve heard good things, but haven?t had the chance to check it out. To be clear, I mean I?ve heard good thing about insomnia (the software). Not insomnia (the trouble sleeping). No one has anything good to say about that.

tjones
2021-06-29 08:33
@mishalalexander20: I put the postman idea on the feature suggestions - feel free to vote for it here: https://pact.canny.io/feature-requests/p/create-a-postman-collection-from-a-pact

mishalalexander20
2021-06-29 08:43
done!

prash471
2021-06-29 09:43
has joined #pact-js

martijn.hagens
2021-06-29 10:12
has joined #pact-js

miguel.carneiro
2021-06-29 10:23
@miguel.carneiro has left the channel

mikko.s.koskinen
2021-06-29 17:05
has joined #pact-js

ali.akbar
2021-06-29 18:21
Hello. I'm in a scenario where I'm hitting a specific path with a get request. I'm receiving no data while hitting the URL `http://localhost:3997/api/courses/v2/blocks/` : ``` { status: 200, data: {}, headers: undefined, config: { url: 'http://localhost:3997/api/courses/v2/blocks/', method: 'get', headers: { Accept: 'application/json, text/plain, */*' }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus], data: undefined }, request: { responseUrl: 'http://localhost:3997/api/courses/v2/blocks/' } }``` Upon `provider.verify()` I'm seeing the following error: ``` console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:122:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /api/courses/v2/blocks/``` Any troubleshooting ideas or where I might've messed up my configurations?

matt.fellows
2021-06-29 22:44
Please share your code so we can tell

matt.fellows
2021-06-29 22:44
It's possibly a promise not handled correctly, or you're not actually sending the request to the pact mock service

matt.fellows
2021-06-29 22:45
Two most common reasons

zhaoyi0113
2021-06-30 02:13
has joined #pact-js

ali.akbar
2021-06-30 06:45
```describe('When a request for *** is made', () => { let id; beforeAll(async () => { const store = await initializeTestStore({ excludeFetchSequence: true }); id = store.getState().***.id; await provider .setup() .then(() => provider.addInteraction({ uponReceiving: 'a request to fetch ***', withRequest: { method: 'GET', path: '/api/courses/v2/blocks/', headers: { Accept: 'application/json' }, }, willRespondWith: { status: 400, body: { root: 'some string', blocks: { some: 'data' }, }, }, })); }); it('should return the correct data', async () => { const authenticatedUser = getAuthenticatedUser(); const url = new URL(`http://localhost:${port}/api/courses/v2/blocks/`); const response = await getAuthenticatedHttpClient().get(url.href, {}); console.log(response); expect(response).toBeTruthy(); }); afterEach(() => provider.verify()); afterAll(() => provider.finalize()); });```

ali.akbar
2021-06-30 06:48
port is 3997. Common for both pact object and get request I'm making.

matt.fellows
2021-06-30 06:56
what does the pact.log file show?

matt.fellows
2021-06-30 06:56
also, i?d recommend not hard coding the port, this way you reduce the chances of port conflicts

ali.akbar
2021-06-30 06:59
These are from the logs (editing out some confidential info): ```I, [2021-06-30T11:50:23.036359 #600] INFO -- : Registered expected interaction GET /api/courses/v2/blocks/ D, [2021-06-30T11:50:23.036600 #600] DEBUG -- : { "description": "a request to fetch course", "request": { "method": "GET", "path": "/api/courses/v2/blocks/", "headers": { "Accept": "application/json" } }, "response": { "status": 400, "headers": { }, "body": { "root": "block-v1:edX+DemoX+Demo_Course+type@course+block@course", "blocks": { some: "data" } } }, "metadata": null } W, [2021-06-30T11:50:23.106900 #600] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api/courses/v2/blocks/ W, [2021-06-30T11:50:23.106958 #600] WARN -- : Missing requests: GET /api/courses/v2/blocks/ I, [2021-06-30T11:50:23.127032 #600] INFO -- : Cleared interactions```

ali.akbar
2021-06-30 07:00
Also, is there a better way to set ports? Would be awesome to know.

matt.fellows
2021-06-30 07:05
so that?s pretty definitive, it didn?t receive the request

matt.fellows
2021-06-30 07:05
don?t set the port, and one will be generated

matt.fellows
2021-06-30 07:05
the server and port are returned in the `setup()` call

ali.akbar
2021-06-30 07:16
Hmm, so what am I lacking currently? I'm already hitting url as shown in console: ```get http://localhost:3997/api/courses/v2/blocks/```

matt.fellows
2021-06-30 07:39
Can you please share more of the test? I can?t really diagnose without more info

ali.akbar
2021-06-30 07:41
Umm, that's literally it. I haven't written anything other than this at the start: ```const port = 3997; const provider = new Pact({ consumer: 'consumer', provider: 'provider', port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'INFO', });```

matt.fellows
2021-06-30 07:48
is something else running on port `3997`? I can see you?re getting back a `200` but telling pact to return a `400`. So that tells me it?s actually hitting another server

matt.fellows
2021-06-30 07:48
`lsof -i :3997`

matt.fellows
2021-06-30 07:48
if on a mac, that should tell you any processes running that port


ali.akbar
2021-06-30 07:49
No, I don't see anything running on 3997. (ran `lsof -i :3997`)

ali.akbar
2021-06-30 07:50
Yes, I will definitely use the dynamic port allocation once this problem solves. :thumbsup:

matt.fellows
2021-06-30 07:52
I would say do the port allocation thing now, because something is definitely listening on 3997

ali.akbar
2021-06-30 07:53
Right! I'm changing it right now.

ali.akbar
2021-06-30 08:15
I'm a bit confused about maybe a basic contract based testing question now, is this the expected behavior of the tests that I still get no data in response? ```{ status: 200, data: {}, headers: undefined, config: { url: 'http://localhost:53036/api/courses/v2/blocks/', method: 'get', headers: { Accept: 'application/json, text/plain, */*' }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus], data: undefined }, request: { responseUrl: 'http://localhost:53036/api/courses/v2/blocks/' } }``` But the good thing is, the tests are now passing on `provider.verify()` :raised_hands:

matt.fellows
2021-06-30 08:18
I?m confused about `status: 200`. You?re setting it to return `400` - what does `const response = await getAuthenticatedHttpClient().get(url.href, {});` actually do?

matt.fellows
2021-06-30 08:18
I?d also suggest setting the correct content-type header, many http clients won?t read a JSON body unless it is the correct type e.g. `application/json`

matt.fellows
2021-06-30 08:19
I have to run (dinner time here) but will keep an eye open

ali.akbar
2021-06-30 08:23
(Oh, sorry to keep you up late.) `getAuthenticatedHttpClient().get(url.href, {});` makes a get request to a URL. I think I should try axios maybe.

matt.fellows
2021-06-30 09:14
I would recommend getting a minimal viable example with axios working and then adding your client in

matt.fellows
2021-06-30 09:14
Or even starting with the examples in pact JS

matt.fellows
2021-06-30 09:14
Did you give adding the headers a go?

ali.akbar
2021-06-30 09:32
No, I still get the same empty data with 200. I guess you're right. I'll start all over or maybe use pact-jest which might be a bit better for my usage. Thank you so much for your time.

matt.fellows
2021-06-30 09:35
You're welcome! Keen to get to the bottom of that though

matt.fellows
2021-06-30 09:35
I'll give that example a go later replacing it with axios. Should be able to get a working example pretty quickly

ali.akbar
2021-06-30 09:36
Yeah, I'd surely be back with a solution if I find one :smile:

v-gabriel.dantas
2021-06-30 20:23
hey guys, is there any reason why my request body does not show up on my pact file? Without the body, I cant verify my provider

phil.endsley
2021-06-30 20:24
We would need to see how the it's defined, not the generated contract

v-gabriel.dantas
2021-06-30 20:25
@phil.endsley

phil.endsley
2021-06-30 20:30
On my phone, so sorry I can't format better. I don't think you should have the data property under `withRequest`

v-gabriel.dantas
2021-06-30 20:31
no prob man

phil.endsley
2021-06-30 20:31
Should be body instead I think

v-gabriel.dantas
2021-06-30 20:31
hum

v-gabriel.dantas
2021-06-30 20:31
let me see

matt.fellows
2021-06-30 22:52
it should be `body`


abubics
2021-07-01 00:45
`data` might be how it's exposed in your http client (which Pact has no knowledge of)

matt.fellows
2021-07-01 02:09
Yeah, I think axios and others use data

zhaoyi0113
2021-07-01 04:25
Hi guys, I am using the order example from https://docs.pact.io/5-minute-getting-started-guide. When looking at consumer side, I see there is a `orderClient.js` and a test case `will receive the list of current orders`. I don?t understand why we need that in consumer side. I thought consumers only need to publish the pacts json file to provider to run the test case. What is the reason for running test cases in consumers side?

tjones
2021-07-01 05:10
Check out this excellent series of diagrams from the people at Pactflow: https://pactflow.io/how-pact-works/#slide-1

tjones
2021-07-01 05:11
The reason tests exist on the client side (before the pact file is written) is so that we can be sure that the consumer: 1) is able to generate the request that we expect 2) is able to understand the response that we expect

tjones
2021-07-01 05:12
It's this feature that gives pact more deployment confidence than other API mocking tools - because we confirm that the same contract is respected by both sides

tjones
2021-07-01 05:13
If you want more details, we have this in the Pact documentation, too: https://docs.pact.io/getting_started/how_pact_works/

zhaoyi0113
2021-07-01 05:15
great, thanks for that.

sgottipati
2021-07-01 06:02
has joined #pact-js

vshankar
2021-07-01 06:06
has joined #pact-js

e.generalov
2021-07-01 07:19
has joined #pact-js

eduards.klavins
2021-07-01 13:44
has joined #pact-js

eduards.klavins
2021-07-01 13:47
Hey, I am getting some very abstract error from `node-pact` when running this thing with jest in nove environment: do you have a clue what is it? ``` FAIL src/__tests__/onmessage-contract.spec.ts WebSocket consumer tests ? bo.TableState_open (31 ms) ? WebSocket consumer tests ? bo.TableState_open thrown: "" 22 | }) 23 | > 24 | it("bo.TableState_open", async() => { | ^ 25 | return messagePact 26 | .expectsToReceive("bo.TableState") 27 | .withContent({ at src/__tests__/onmessage-contract.spec.ts:24:5 at Object.<anonymous> (src/__tests__/onmessage-contract.spec.ts:16:1) [2021-07-01 12:43:18.751 +0000] INFO (1660 on PCNAME.local): pact@9.16.0: Verifying message [2021-07-01 12:43:18.753 +0000] INFO (1660 on PCNAME.local): pact-node@10.12.2: Creating Message [2021-07-01 12:43:18.754 +0000] INFO (1660 on PCNAME.local): pact-node@10.12.2: Creating message pact [2021-07-01 12:43:18.776 +0000] ERROR (1660 on PCNAME.local): pact-node@10.12.2: errno: -2 code: "ENOENT" syscall: "spawn standalone/darwin-1.88.49/pact/bin/pact-message" path: "standalone/darwin-1.88.49/pact/bin/pact-message" spawnargs: [ "update", "--consumer", "TOSClient", "--pact_dir", "/Users/UNAME/PKG_PATH/pacts", "--provider", "BackofficeAPI", "--pact_specification_version", "3" ] [2021-07-01 12:43:18.779 +0000] WARN (1660 on PCNAME.local): pact-node@10.12.2: Pact exited with code -2. [2021-07-01 12:43:18.779 +0000] INFO (1660 on PCNAME.local): pact-node@10.12.2: Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 1.893 s, estimated 3 s Ran all test suites matching /src\/__tests__\/onmessage-contract.spec.ts/i.```

tjones
2021-07-01 13:50
This is saying that the pact-node install hasn?t been successful. Try removing node_modules and doing `npm install` again.

eduards.klavins
2021-07-01 13:51
I am using yarn berry and pnp - is that combo supported? I dont have any node_modules anymore

tjones
2021-07-01 13:51
This happens if the binary is missing.

tjones
2021-07-01 13:52
It is supported, but lots doesn?t work with berry and pnp

tjones
2021-07-01 13:53
It should install correctly with yarn/berry. But you can?t tell if it worked or not because they suppress all output from scripts.

eduards.klavins
2021-07-01 13:54
I did `yarn cache clean --all` and then `yarn install` again but still getting the same errors. Install goes successfully. :confused:

tjones
2021-07-01 13:54
I forget where the path is that yarn unpacks to, but clean that and do a reinstall

tjones
2021-07-01 13:54
I don?t think it?s the cache

tjones
2021-07-01 13:55
I couldn?t get pact working with yarn pnp because of unrelated issues. My view is that yarn?s experimental release is broken

tjones
2021-07-01 13:55
But, if you have gotten this far, the binary should be there and working

tjones
2021-07-01 13:55
We had a thread about it last week

eduards.klavins
2021-07-01 13:56
Yea, other devs on my team have no issues so I think this could work: > I forget where the path is that yarn unpacks to, but clean that and do a reinstall Will give you an update :wink:


tjones
2021-07-01 13:56
Here?s the thread

tjones
2021-07-01 13:57
My conclusion is: 1) Yarn is broken 2) if there?s something we can change to improve the experience for yarn users please let us know and we?ll do it

tjones
2021-07-01 13:59
Yarn berry keeps the packages zipped unless they have postinstall scripts

tjones
2021-07-01 13:59
So it will unpack pact-node so that it can go get the correct binaries

tjones
2021-07-01 14:00
I think it?s a hidden folder in the project directory, but I am not at my computer to check

eduards.klavins
2021-07-01 14:01
~|~

eduards.klavins
2021-07-01 14:08
Got: `@pact-foundation/pact-node@npm:10.12.2 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/mb/tf9xgkzd0bl2g5_1y2f7fv84jg9s7n/T/xfs-e0e6e6d5/build.log` And those logs say: ```# This file contains the result of Yarn building a package (@pact-foundation/pact-node@npm:10.12.2) # Script name: postinstall Installing Pact Standalone Binary for darwin. Downloading Pact Standalone Binary v1.88.49 for platform darwin from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.49/pact-1.88.49-osx.tar.gz Please note: we are tracking this download anonymously to gather important usage statistics. To disable tracking, set 'pact_do_not_track: true' in your package.json 'config' section. Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error downloading binary from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.49/pact-1.88.49-osx.tar.gz: Error: Error while installing binary: Error: self signed certificate in certificate chain at throwError (/Users/eduardsk/Development/games/.yarn/unplugged/@pact-foundation-pact-node-npm-10.12.2-cc2bb34b6a/node_modules/@pact-foundation/pact-node/standalone/install.js:40:11) at /Users/eduardsk/Development/games/.yarn/unplugged/@pact-foundation-pact-node-npm-10.12.2-cc2bb34b6a/node_modules/@pact-foundation/pact-node/standalone/install.js:335:16 at processTicksAndRejections (node:internal/process/task_queues:94:5) ``` What are those cert errors?

2021-07-01 14:08
Please see these instructions on running and accessing a Pact Broker over TLS https://docs.pact.io/pact_broker/advanced_topics/using-tls/

felix.gomez
2021-07-01 14:38
has joined #pact-js

dimundo
2021-07-01 15:17
nice to see a colleague here :smile: @eduards.klavins :hand:

david.vancouvering
2021-07-01 17:07
:thumbsup:

v-gabriel.dantas
2021-07-01 18:44
hey guys, do you know if there is a way to ignore some values from the response provider when I try to verify it?

dimundo
2021-07-01 18:54
wrap with `like` in consumer ?

dimundo
2021-07-01 18:55
but you need to understand what will happen :slightly_smiling_face:

dimundo
2021-07-01 18:55
or regexp power

dimundo
2021-07-01 18:55
( also there are some predefined :wink: )

v-gabriel.dantas
2021-07-01 18:56
cool

v-gabriel.dantas
2021-07-01 18:57
what will happen if I use the `like` function wrapped in my consumer body?

dimundo
2021-07-01 18:59
most probably 1st one will match any int, 2nd any string - depends on consumer https://docs.pact.io/getting_started/matching/

bbako
2021-07-01 20:51
has joined #pact-js

tjones
2021-07-01 23:32
In general, if you need to ignore something from the provider (as in, the consumer doesn't care about it), just don't include it in the pact.

tjones
2021-07-01 23:32
The pact should only contain things the consumer needs, which means that it's not safe to ignore fields

matt.fellows
2021-07-01 23:33
This looks like you have proxies in the way


matt.fellows
2021-07-01 23:35
@tjones actually ran into another proxy problem yesterday. I'll raise an issue for an idea I have to get better visibility into that. But this shows the upside of bundling the package

tjones
2021-07-01 23:40
Yep. We'll still have problems with Yarn 2, but I don't think that's easy to avoid.

tjones
2021-07-01 23:41
The ruby binaries compress really well. I was thinking we could ship them compressed (inside the package) and then uncompress as needed

matt.fellows
2021-07-01 23:48
Makes sense to me.

matt.fellows
2021-07-01 23:48
It would solve problems for people right now

matt.fellows
2021-07-01 23:48
> Yep. We?ll still have problems with Yarn 2, but I don?t think that?s easy to avoid. I don?t know the ins/outs of this. What?s the TL;DR?

v-gabriel.dantas
2021-07-01 23:49
hum, thats a great idea @tjones

v-gabriel.dantas
2021-07-01 23:49
Thanks a lot

phil.armstrong
2021-07-02 06:49
has joined #pact-js

eduards.klavins
2021-07-02 06:51
Can confirm that install works with disabled proxy? :raised_hands: Thanks!

matt.fellows
2021-07-02 06:52
:thumbsup:

matt.fellows
2021-07-02 06:52
gah, proxy!

matt.fellows
2021-07-02 06:54
did you disable it via something like  `no_proxy` and `NO_PROXY` to `localhost,::1,127.0.0.1` ?

matt.fellows
2021-07-02 06:54
I?d like to add to our readme/debugging guide

eduards.klavins
2021-07-02 07:16
I disabled our corporate client tool on startup :shushing_face: :smile:

matt.fellows
2021-07-02 07:16
ahhh :stuck_out_tongue:

eduards.klavins
2021-07-02 07:16
But - I suspect this might work as well - `export NODE_TLS_REJECT_UNAUTHORIZED=0`

matt.fellows
2021-07-02 07:17
possibly

matt.fellows
2021-07-02 07:17
but also :scream:

gargshubham49
2021-07-02 07:21
has joined #pact-js

dimundo
2021-07-02 07:37
yes, we have some ~mitm~ security , sadly

aubilla
2021-07-02 09:58
:wave: I?m trying to write Consumer tests for this client that calls a service that returns a PDF. ```import { all, call, put, takeLatest } from 'redux-saga/effects'; import axios, { AxiosResponse } from 'axios'; import { fetchPdf } from '../actions'; const fetchPdfWorker = function* (action: any) { try { const fileId = action.payload; yield put(fetchPdf.request()); let { data }: AxiosResponse<Blob> = yield call( axios.get, `/api/reporting/rendering-service/render/${fileId}`, { responseType: 'blob' }, ); yield put( fetchPdf.success(data), ); } catch (error) { yield put(fetchPdf.failure(error)); } finally { yield put(fetchPdf.fulfill()); } }; export default function* run() { yield all([ takeLatest(fetchPdf, fetchPdfWorker), ]); }``` I?m following https://docs.pact.io/implementation_guides/javascript/readme guide and https://github.com/pact-foundation/pact-js/blob/master/examples/typescript/test/get-dog.spec.ts example but I have issues injecting the mock url into a Provider that?s not a class but a Generator function. Do you have an example implementation that would be closer to what I have? Sorry for the n00b question but I?m a Java developer and I?ve discovered JavaScript yesterday :eyes:

eduards.klavins
2021-07-02 10:41
Hey, I have an interesting case here I believe - couldn?t find any examples here. I have a REST endpoint that I am fetching via WebWorker off the main thread - my app sends a `worker.postMessage` to initiate the GET request and then later I would listen to a message from webWorker when data has been fetched. How would I go about writing correct pacts for that? https://github.com/pact-foundation/pact-js/blob/master/examples/jest/__tests__/index.spec.js seems quite basic regarding API calls

dimundo
2021-07-02 10:42
you need ? pact for initial message ? pact for get ? pact for 2nd message


dimundo
2021-07-02 10:43
pact doesnt care about side-effects

eduards.klavins
2021-07-02 10:44
Why? WebWorker is not an ?external? body that I need to communicate with. My get request calls are just ?obfuscated? in webworker and i have no way to directly initiate get request in my code without doing it via webworker

dimundo
2021-07-02 10:44
but you expect some message, right ?

dimundo
2021-07-02 10:45
then you need ? pact for initial message ( as a provider ) ? ~pact for get~ ? pact for 2nd message ( as a consumer )


eduards.klavins
2021-07-02 10:47
1. Frontend app sends a message to webworker(who is still part of FE app) to initiate get request. It is a SYNChronous call 2. WebWorker makes `window.fetch` GET request (async) 3. WebWorker posts message back to frontend app (sync)

tjones
2021-07-03 05:34
I don?t have experience with webworkers for this, but those feel like separate concerns

tjones
2021-07-03 05:34
How do you normally test the webworker boundary?

tjones
2021-07-03 05:35
I would write: Pact test within the webworker for the request/response Regular test for the webworker boundary

tjones
2021-07-03 05:36
If you can?t do that, can you wrap the request/response parts of the webworker in a promise for the purpose of testing?

tjones
2021-07-03 05:37
If you?re able to share some code that includes this webworker pattern, we can give more direct help

tjones
2021-07-03 05:40
It?s a bit hard to help you inject the base url, since that?s more an implementation question for you/your engineers (how are you doing it with the real url?)

tjones
2021-07-03 05:41
But in general, I think there are two concerns there- one is the interface to redux, and the other is the api call. I would separate those out, as it will then be much easier to test and reason about

aubilla
2021-07-05 12:26
Thanks Timothy!

vinnys.lins
2021-07-05 13:49
has joined #pact-js

zhaoyi0113
2021-07-06 00:31
Hi There, I am using nodejs pact and I found there is a field `uponReceiving` used in the example when calling `provider.addInteraction` in consumer test case. But I can?t find what this field mean in the doc. Does it mean anything?

matt.fellows
2021-07-06 00:32
It is the test description, used to differentiate the various scenarious you are testing

matt.fellows
2021-07-06 00:32
e.g. `uponReceiving` ?a request to get a user?

matt.fellows
2021-07-06 00:32
the state then allows you to test various scenarios

matt.fellows
2021-07-06 00:33
`given` ?a user with ID 1234 exists? or ?a team with ID 5678 exists?

zhaoyi0113
2021-07-06 00:35
so it is just a description? it doesn?t have much impact on the logic?

tjones
2021-07-06 00:36
It's just a description - it appears in the test summary in the broker

matt.fellows
2021-07-06 00:36
whilst it?s not a functional aspect of the test, it?s important like naming and describing any test is important. Perhaps even more so, because the provider side will use it to understand what?s going on.

tjones
2021-07-06 00:36
You'll need to ensure that the same description isn't used for different requests.

matt.fellows
2021-07-06 00:36
Think of Pact as building up a description of how your system is integrated

tjones
2021-07-06 00:37
as in you can't be like: "a post to create a user" with two different bodies

zhaoyi0113
2021-07-06 00:38
yes for sure, thanks

zhaoyi0113
2021-07-06 00:38
got it, thanks guys.

tjones
2021-07-06 00:41
I usually keep the `uponReceiving` and `withRequest` together - see for example here: https://github.com/pact-foundation/jest-pact#best-practices

zhaoyi0113
2021-07-06 00:42
make sense thanks

talank
2021-07-06 03:52
has joined #pact-js

tausif2909
2021-07-06 04:49
TypeError: Cannot read property 'log Level' of undefined at Verifier V3.validate Configuration Hello, I get this error while running providerVerification.js , How do I resolve it? Below is the complete error:

matt.fellows
2021-07-06 04:49
sounds like a bug, what does your code look like?

tausif2909
2021-07-06 05:08
```D:\git-directory\tag-service\AcceptanceTests\pact>node providerVerification.spec.js http://192.168.99.101:18132 D:\git-directory\tag-service\AcceptanceTests\node_modules\@pact-foundation\pact\src\v3\verifier.js:65 if (this.config.logLevel && !ramda_1.isEmpty(this.config.logLevel)) { ^ TypeError: Cannot read property 'logLevel' of undefined at VerifierV3.validateConfiguration (D:\git-directory\tag-service\AcceptanceTests\node_modules\@pact-foundation\pact\src\v3\verifier.js:65:25) at new VerifierV3 (D:\git-directory\tag-service\AcceptanceTests\node_modules\@pact-foundation\pact\src\v3\verifier.js:36:14) at Object.<anonymous> (D:\git-directory\tag-service\AcceptanceTests\pact\providerVerification.spec.js:97:8) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) at internal/main/run_main_module.js:17:47```

tjones
2021-07-06 05:26
Are you passing options to `new VerifierV3(opts)`?

tjones
2021-07-06 05:27
Which version of pact-js are you using?

tausif2909
2021-07-06 05:49
I am using `const { VerifierV3 } = require('@pact-foundation/pact/v3');`

bethskurrie
2021-07-06 05:49
@tonynguyenit18 this is probably the longest time I've ever gone between Pact Broker releases, but it's finally out. Please upgrade to 2.80.0.0

tausif2909
2021-07-06 05:49
Error got resolved when I have removed all console.log from the file

tausif2909
2021-07-06 05:50
Previously it was like below

tausif2909
2021-07-06 05:50
```console.log(opts.providerBaseUrl); return new Verifier().verifyProviderV3(opts).then(output => { console.log('Pact Verification Complete!'); console.log(output);```

tausif2909
2021-07-06 05:51
Then I passed simply :`return new VerifierV3(opts).verifyProvider();` Then error got resolved

tausif2909
2021-07-06 06:29
Hello, While running the `providerVerification.js` , Its throwing below error :

tausif2909
2021-07-06 06:30
``` node providerVerification.spec.js [2021-07-06 06:25:16.638 +0000] WARN (11148 on tshaikh): pact@10.0.0-beta.42: non-local provider address http://192.168.99.101:18132 detected, setting 'changeOrigin' to 'true'. This property c an be overridden. [2021-07-06T06:25:17Z ERROR pact_verifier] Failed to load pact - Could not load pacts from the pact broker 'https://pact.xyz.net/' - LinkError("Link 'pb:provider-pacts-for-verification' was not found in the response, only the following links where found: \"curies, pb:latest-pact-versions, pb:latest-provider-pacts, pb:latest-provider-pacts-with-tag, pb:latest-tagged-version, pb:l atest-version, pb:pacticipants, pb:provider-pacts, pb:provider-pacts-with-tag, pb:publish-pact, pb:webhooks, self\". URL: 'https://pact.xyz.net/', LINK: 'pb:provider-pacts-for-verification' ") Failures: 1) Failed to load pact - Could not load pacts from the pact broker 'https://pact.xyz.net/' - LinkError("Link 'pb:provider-pacts-for-verification' was not found in the response, only the fol lowing links where found: \"curies, pb:latest-pact-versions, pb:latest-provider-pacts, pb:latest-provider-pacts-with-tag, pb:latest-tagged-version, pb:latest-version, pb:pacticipants, pb:provi der-pacts, pb:provider-pacts-with-tag, pb:publish-pact, pb:webhooks, self\". URL: 'https://pact.xyz.net/', LINK: 'pb:provider-pacts-for-verification'") There were 1 pact failures (node:11148) UnhandledPromiseRejectionWarning: null (Use `node --trace-warnings ...` to show where the warning was created) (node:11148) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promis e which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_u nhandled_rejections_mode). (rejection id: 1) (node:11148) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zer o exit code.```

tausif2909
2021-07-06 06:31
The pactBroker url: `https://pact.xyz.net/` is accessible

matt.fellows
2021-07-06 06:33
What version is it? Are you passing a full URL to a pact file or just the broker URL?

tausif2909
2021-07-06 06:40
```require('bunyan'); require('chai'); require('path'); const request = require('request-promise'); const { version } = require('./../../Service/package.json') //const { Verifier } = require('@pact-foundation/pact'); const { VerifierV3 } = require('@pact-foundation/pact/v3'); // PACT provider verification const opts = { provider: 'flex-tagWIP-service', providerBaseUrl: 'http://192.168.99.101:18132', pactBrokerUrl: 'https://pact.xyz.net/', publishVerificationResult: true, providerVersion: version, stateHandlers: { "All the tags associated with the given assetId will be returned": setup => { // return { assetId: 303 } return Promise.resolve({ assetId: 303 }) }, } }; return new VerifierV3(opts).verifyProvider();``` This is how my code looks like

tjones
2021-07-06 06:40
I don't know what was happening, but I suspect your `opts` was undefined when it was passed to pact. This isn't validated in the `VerifierV3` and it isn't.

tjones
2021-07-06 06:42
Please tell us which version of pact you are using. If you don't know, you can find it with `npm ls @pact-foundation/pact`

tjones
2021-07-06 06:43
Ah, it's in your log: `pact@10.0.0-beta.42`

matt.fellows
2021-07-06 06:43
What version of the pact broker are you running?

matt.fellows
2021-07-06 06:44
That will determine if the feature is supported

tausif2909
2021-07-06 06:49
Sorry, I am not sure which version are you talking about, Do you mean the highlighted one in below screenshot?

matt.fellows
2021-07-06 06:53
No, it looks like you're running your own pact broker. What version is it?

tausif2909
2021-07-06 06:54
or do you mean I need to update the pactBroker version if I am using `pact@10.0.0-beta.42` ?

matt.fellows
2021-07-06 06:55
Yes you might need to. But first it's be good to know what you're on now, it could be a bug

tausif2909
2021-07-06 06:56
```<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ooyala.flex</groupId> <packaging>jar</packaging> <artifactId>pact-broker-client</artifactId> <version>1.0-SNAPSHOT</version> <name>pact-broker-client</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency> <dependency> <groupId>com.jayway.restassured</groupId> <artifactId>rest-assured</artifactId> <version>2.9.0</version> </dependency> </dependencies> </project>``` This is the xml of pact-broker-client

matt.fellows
2021-07-06 06:56
I need the broker version. The screenshot from before is your broker

matt.fellows
2021-07-06 06:58
You can get it from the response headers to any API call, or head to HAL browser and check the version in the header

matt.fellows
2021-07-06 06:59
Sorry on mobile, I'm sure this is documented somewhere on our docs but can't see immediately

tausif2909
2021-07-06 07:04
ok let me find it

tausif2909
2021-07-06 07:05
`x-pact-broker-version: 2.23.4`

tausif2909
2021-07-06 07:19
:point_up_2:@matt.fellows @tjones

matt.fellows
2021-07-06 07:26
Yep that's super old, possibly multiple years. You won't be able to use The new JS client with that version.

matt.fellows
2021-07-06 07:26
You should definitely update to a newer broker because you're missing out on good stuff! Or look at Pactflow if you don't want to manage your own. We do all of that for you :wink:

juri.petersen
2021-07-06 07:29
has joined #pact-js

juri.petersen
2021-07-06 07:34
Hello, I'm trying to get Pact running with Cypress as the testing framework. When invoking ```const provider = new Pact({ consumer: 'Frontend', provider: 'API', port: 8585, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'debug', });``` in a test the error ```1) An uncaught error was detected outside of a test: TypeError: The following error originated from your test code, not from Cypress. > Cannot read property 'replace' of undefined When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. Cypress could not associate this error to any specific test. We dynamically generated a new test to display this failure. at Object.eval (webpack:///./node_modules/@pact-foundation/pact-node/node_modules/mkdirp/lib/use-native.js?:4:25) at eval (webpack:///./node_modules/@pact-foundation/pact-node/node_modules/mkdirp/lib/use-native.js?:12:30) at Object../node_modules/@pact-foundation/pact-node/node_modules/mkdirp/lib/use-native.js (http://localhost:38411/__cypress/src/js/spec-0.js:207:1) at __webpack_require__ (http://localhost:38411/__cypress/src/main.js:64:30) at eval (webpack:///./node_modules/@pact-foundation/pact-node/node_modules/mkdirp/index.js?:6:36) at Object../node_modules/@pact-foundation/pact-node/node_modules/mkdirp/index.js (http://localhost:38411/__cypress/src/js/spec-0.js:141:1) at __webpack_require__ (http://localhost:38411/__cypress/src/main.js:64:30) at Object.eval (webpack:///./node_modules/@pact-foundation/pact-node/src/service.js?:23:14) at eval (webpack:///./node_modules/@pact-foundation/pact-node/src/service.js?:236:30) at Object../node_modules/@pact-foundation/pact-node/src/service.js (http://localhost:38411/__cypress/src/js/spec-0.js:886:1)``` occurs. I am running `"@pact-foundation/pact": "^9.16.0"` . Is this error caused by configuration mistakes?

leolvicario
2021-07-06 07:36
has joined #pact-js

tausif2909
2021-07-06 07:46
Which should be the suitable version for pact-broker?

matt.fellows
2021-07-06 07:47
Well I'd just upgrade to the latest

abubics
2021-07-06 08:15
Firstly, are you doing something like this? https://pactflow.io/blog/cypress-pact-front-end-testing-with-confidence/ Or are you trying to create contracts from UI-driven tests?

juri.petersen
2021-07-06 08:36
At the moment I am trying to test API endpoints in unit tests driven by Cypress. It may look like this https://github.com/pactflow/example-consumer-cypress/blob/master/cypress/integration/test/products.js but without the setup of cypress commands.

juri.petersen
2021-07-06 08:37
Its not really anything but invoking `new Pact()` in a unit test with cypress. But this fails with the given error.

tjones
2021-07-06 08:43
It looks like it?s failing because the OS calls aren?t available during a UI test. I don?t know much about Cypress, but try the guide that Boris linked.

tjones
2021-07-06 08:43
In general, though, I would say that testing API calls through the UI sounds like the kind of integration test that Pact is designed to eliminate.

tjones
2021-07-06 08:44
I think it would be better to test your API layer with Pact outside the context of Cypress.

swoichhaa
2021-07-06 08:46
has joined #pact-js

juri.petersen
2021-07-06 08:50
Thank you for the feedback!

matt.fellows
2021-07-06 09:05
What Tim said

matt.fellows
2021-07-06 09:05
but also?



matt.fellows
2021-07-06 09:06
So you can do it, just make sure you?re not doing it the wrong way (link in that article about a tale of woe to scare you into doing it properly?if you do)

matt.fellows
2021-07-06 09:06
Also, dirty secret, we do this at Pactflow :stuck_out_tongue:

ivo.velthoven174
2021-07-06 09:28
has joined #pact-js

abubics
2021-07-06 09:44
I've skimmed the article and the readme, but I'm a bit confused (maybe reading them properly would resolve :yay:) . . . I initially thought it was saying to generate the pacts through unit tests (as usual), and then use the pact file with the stub provider in the UI tests (to avoid making calls to real APIs). But the readme sounds like it's running the UI tests at the same time as exercising the pact bits to generate the contract.

matt.fellows
2021-07-06 09:46
Could probably make that clearer

matt.fellows
2021-07-06 09:47
you can do it in 3 ways: 1. Do it in the usual way, then use Pact stubs instead of Cypress stubs 2. Do Pact tests in Cypress (using the Pact interface though, not the Cypress interface). That?s what the example repo does, and actuallly what we do in Pactflow 3. Use Cypress mocks, but serialise them to a pact file and use that as the contract

matt.fellows
2021-07-06 09:47
1 is the safest, but arguably not a nice experience for Cypress users

matt.fellows
2021-07-06 09:47
(2) is a decent compromise - best safety guarantees, and still a fairly straightforward experience with Cypress

matt.fellows
2021-07-06 09:47
(3) is the best Cypress experience, but you will make it very hard for your providers, so you shouldn?t do this, unless you *really* know what you?re doing.

matt.fellows
2021-07-06 09:48
OR you are using the https://docs.pactflow.io/docs/workshops/bi-directional/ feature of Pactflow, which reduces the guarantees with the upside of a simpler overall experience (on both sides)

abubics
2021-07-06 09:48
that's a nice breakdown, and I completely agree xD I hadn't even considered (3) before :open_mouth:

matt.fellows
2021-07-06 09:49
I should put that summary into that article

abubics
2021-07-06 09:56
Also :taco: for @matt.fellows, not just useful info to answer the question, but helpful for everyone else in the thread, too!

matt.fellows
2021-07-06 09:59
I?m proctrastinating, I should be reviewing your talk :wink:

matt.fellows
2021-07-06 10:02
Also, updated that article just now

abubics
2021-07-06 10:18
I'm procrastinating, I should be finishing it :joy:

fjtdg
2021-07-06 12:16
has joined #pact-js

juri.petersen
2021-07-06 12:31
Thanks for the helpful answers! I followed https://github.com/pactflow/example-consumer-cypress and after setting up everything and fixing a few errors caused by me, the same error comes up again.

juri.petersen
2021-07-06 12:44
For further context: I am trying to set this up in a vue3 application.

matt.fellows
2021-07-06 13:36
Could you please share your code? This is not a standard use case so we'll need more information

matt.fellows
2021-07-06 13:36
Also apologies, both links I shared were already discussed above. I think because slack collapsed the thread I didn't see it.

matt.fellows
2021-07-06 13:37
Anyhow, happy to take a look at your setup if you can share

matt.fellows
2021-07-06 13:38
It does seem like it's trying to run in a browser environment or at least a non-node environment

matt.fellows
2021-07-06 13:38
Pact needs to run on node

matt.fellows
2021-07-06 13:39
Not running a new Mac M1 chip?

steve.etherington
2021-07-06 16:44
has joined #pact-js

matt.fellows
2021-07-07 04:57
@tausif2909 how did you go with the injected provider states example?

matt.fellows
2021-07-07 04:58
> How do I modify my request to pass the real ${assetId} while running the provider verification in the nodejs You return them in the provider state: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/provider-state-injected/provider/account-service.test.js#L31-L33

tausif2909
2021-07-07 05:13
As suggested by you, I need to update the pact-broker, I have raised the ops ticket to upgrade the same, our ops team is taking care of that, So I need to wait till that time:stuck_out_tongue_closed_eyes:

rosh.mjohn
2021-07-07 07:19
has joined #pact-js

rosh.mjohn
2021-07-07 07:23
Hi there. I'm trying to write consumer driven contract tests in node. For the provider verification step, can we pass in the specific consumer version that needs to be verified with the provider?

matt.fellows
2021-07-07 07:26
Have you read about tags?

rosh.mjohn
2021-07-07 07:37
I'm more concerned about the consumer version number than the tags. I found these verification options in the docs, couldn't find reference to consumer version.

matt.fellows
2021-07-07 07:39
Can you please explain why? It's an unusual use case

dimundo
2021-07-07 07:49
one must not mix consumer version and tag - they are very different beasts

matt.fellows
2021-07-07 07:53
you almost certainly don?t want to use versions. If you need that level of coupling, best just to pass the exact URL of the pact you need to verify (which you can do via webhooks anyway)

matt.fellows
2021-07-07 07:53
See the CI/CD workshop in howtolearn for best practices on integrating to your deployment pipeline

2021-07-07 07:53
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

juri.petersen
2021-07-07 08:22
Its a vue setup. Unfortunately I cant really share it at the moment. I fixed it to where the Pact MockServer is running. Integrations do not work yet but I guess thats going to need fixing on my side.

mahajanalokkumar
2021-07-07 10:41
has joined #pact-js

dawoud.sheraz
2021-07-07 18:50
Hello. A question about writing consumer tests with pact-js and jest. When attempting to add interaction, what is the possibility that test will execute before the interaction can setup? I am using await when adding interaction but from the logs, it seems the test executes before the interaction can setup.

dawoud.sheraz
2021-07-07 18:51
Log sequence: ```INFO -- : Registered expected interaction GET /api/items/ WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api/items/ W, [2021-07-07T23:45:05.208260 #59740] WARN -- : Missing requests: GET /api/items/ I, [2021-07-07T23:45:05.220478 #59740] INFO -- : Cleared interactions```

jyiyng2002
2021-07-07 19:57
has joined #pact-js

splurgeop
2021-07-07 21:48
has joined #pact-js

kapoor.manil
2021-07-07 22:30
has joined #pact-js

matt.fellows
2021-07-07 23:06
badpromise


matt.fellows
2021-07-07 23:07
if you can share the code, we can take a look

matt.fellows
2021-07-07 23:07
but that is the key symptom of incorrect promise handling

abubics
2021-07-08 00:40
Also (aside), if you're using `pact-js` + `jest`, you might want to try `jest-pact` to simplify a little

pashas.2k3
2021-07-08 03:41
has joined #pact-js

dawoud.sheraz
2021-07-08 04:02
thank you, I will confirm the bad promise bit.

vijayanaggella
2021-07-08 05:25
has joined #pact-js

tausif2909
2021-07-08 05:41
Hi there , I have such huge array json response to add matchers on the consumer side, Just need a suggestion what would be a best approach to add matchers fo such long and complex json, Also at provider side it won't be having that many items in the array, Can we add such matcher that it would verify only first item in the array and ignore other elements?

matt.fellows
2021-07-08 05:44
yes, take a look at the `eachLike` matcher. They all appear to have the same structure, so you could just do something like: ``` eachLike({ "displayName": "New Text 2", "name": "metadata-10128.var-text-new-text-2", "fqlName": "metadata-10128.var-text-new-text-2", "filterType": "string", "dataType": "text", "schema": { "id": 10128, "displayName": "Medium" }, "category": "custom", "filterKey": "metadata-10128.var-text-new-text-2" })```

matt.fellows
2021-07-08 05:44
that says the provider must have `1 or more` items that have those keys with the same _type_

ananthshenoy03
2021-07-08 05:46
has joined #pact-js

tausif2909
2021-07-08 05:57
Just one confusion, How it will still generate such huge json on the consumer side?

tausif2909
2021-07-08 06:00
I have the code written like this.... Not sure How to use `eachLike` here

matt.fellows
2021-07-08 06:06
does it need to generate a big one?

tausif2909
2021-07-08 06:10
Yes, Because this json is being used by the acceptance test further, So I cant change it

matt.fellows
2021-07-08 06:11
You can do `eachLike({?}, min)`

matt.fellows
2021-07-08 06:11
where min can be as many as you like

tausif2909
2021-07-08 06:30
ok, thanks @matt.fellows let me try that

matt.fellows
2021-07-08 06:38
FWIW I always wanted to implement a version of `eachLike` that randomises the data on the consumer side (e.g. using something like `faker`) but has the matchers in it for the provider side

matt.fellows
2021-07-08 06:38
@tjones or @bethskurrie can tell me if that?s a stupid idea :point_up:

sai5i.islam
2021-07-08 06:40
has joined #pact-js

tjones
2021-07-08 07:01
I would do as Matt suggested, where the eachLike generates the examples for you.

bethskurrie
2021-07-08 07:01
it would make a new pact each time

bethskurrie
2021-07-08 07:02
if I understand you correctly Matt.

tjones
2021-07-08 07:02
It's worth thinking about what is under test - Pact is about validating that the consumer and the provider can talk to each other. In general (but not always), it's more about validating that the shape of the data is correct, rather than the exact data is correct

bethskurrie
2021-07-08 07:03
It would negate all the benefits of being able to re-use the pact content to have pacts pre-verified.

bethskurrie
2021-07-08 07:03
Personally, I don't like random data in a test, because it makes the expectations very hard to write.

matt.fellows
2021-07-08 08:54
No, I'm suggesting we could return dynamic mocked data but persist a fixed data set into the contract. Admittedly feels like moving away from contract testing a touch, but I've come across cases where each mocked response needs to actually be different from each other - pact will just return X number of the exact same thinf

matt.fellows
2021-07-08 08:55
The dynamic mocked data must obviously be based on the contract definition, so it's essentially a v3 generator

poorvasgokhale
2021-07-08 09:08
has joined #pact-js

suresh.thammishetti
2021-07-08 11:08
has joined #pact-js

zhaoyi0113
2021-07-08 11:31
Hello guys, a quick question about provider verification: when run pact verify in provider side, if there are multiple consumers pacts in the broker, will provider verify runs in parallel or in sequence?

matt.fellows
2021-07-08 11:32
It will run them sequentially. The order of contract (and interactions) within them is non-deterministic

zhaoyi0113
2021-07-08 11:35
oh, it doesn?t run them in the same order from the `pacts file`?

matt.fellows
2021-07-08 11:36
it?s implementation dependent, but it?s best to assume (and design for) that it?s non deterministic

matt.fellows
2021-07-08 11:36
One of the fundamental aspects of pact, is that each interaction should be independent of all others

zhaoyi0113
2021-07-08 11:37
ok I see thanks.

tjones
2021-07-09 03:05
> Admittedly feels like moving away from contract testing a touch, but I've come across cases where each mocked response needs to actually be different from each other - pact will just return X number of the exact same thinf I think a better approach might be: ```eachLike( someTemplate, populatedExampleArray )```

tjones
2021-07-09 03:08
for example: ```eachLike ( { id: integer(), name: string() }, [{id: 1, name: "foo"}, {id: 2, name: "bar"}])```

matt.fellows
2021-07-09 03:21
agree!


zhaoyi0113
2021-07-09 09:11
Hello, I am checking how to pass access token when publishing pacts but this doc https://docs.pact.io/provider/handling_auth doesn't provider much examples. Provider needs to check whether a token in the request's header is valid before processing the request. This token is short live which means it needs to be generated at run time. so it is not possible to put the token as part of `pact`. Is there an example to see how to pass a runtime token in a middleware when provider verifies the pacts?


matt.fellows
2021-07-09 10:00
The JS workshop also covers this scenario

matt.fellows
2021-07-09 10:00
(howtolearn)

2021-07-09 10:00
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-07-09 10:00
I'm keen for feedback as to why they weren't discoverable to you (not a criticism I'm genuinely keen to understand so that we can fix)

michael.katende
2021-07-09 10:41
has joined #pact-js

marcin.baranowski953
2021-07-09 10:42
has joined #pact-js

uladzislau_danilchyk
2021-07-09 10:47
Hi everyone! I have a question regarding verification reports. Is there any possibility to group reports by consumer tag if passed multiple consumer tags or I need to write custom reporter? For example: I run the verification test and pass property `pactbroker.consumerversionselectors.tags` equal to `branch-tag-1,branch-tag-2` . But in reports If some contract of any tag was failed I can't determine for which tag it was failed. I need to open `html report` -> `Standart Output` tab to determine it instead of searching failed tests in `Tests` tab as usual with printed tag along with version. Thanks in advance!

matt.fellows
2021-07-09 10:52
what are these ?tabs? that you are talking about sorry?

zhaoyi0113
2021-07-09 11:09
sorry, I didn?t find it mentioned in this pact-js doc. I only read this doc: https://docs.pact.io/provider/handling_auth.

zhaoyi0113
2021-07-09 11:12
@matt.fellows, a little more thought about this. If I create 3 interaction in consumer side: 1. create an user 2. update the user 3. delete the user If they can run in order, I don?t need to mock any data in provider side. But if they can run in any order, provider has to mock the data for each interaction. That brings a bit effort to provider side.

uladzislau_danilchyk
2021-07-09 11:31
reports generated by Gradle

matt.fellows
2021-07-09 11:33
Ah, that makes more sense. Probably best asking this in the #pact-jvm channel

matt.fellows
2021-07-09 11:54
so why use Pact? Might as well just do end-to-end tests!

bedfordwest
2021-07-10 22:21
has joined #pact-js

ananthshenoy03
2021-07-11 07:41
Hello, I'm trying to get Pact running with VS code as the testing framework. When I run the command npm start in the terminal I get the following error ```react-scripts start sh: 1: react-scripts: not found npm ERR! Linux 4.4.0-190-generic npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start" npm ERR! node v6.17.1 npm ERR! npm v3.10.10 npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! consumer@0.1.0 start: `react-scripts start` npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the consumer@0.1.0 start script 'react-scripts start'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the consumer package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! react-scripts start npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs consumer npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls consumer npm ERR! There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install? npm ERR! Please include the following file with any support request: npm ERR! /home/ananthshenoy/devhome/demopact/example-consumer/npm-debug.log```

ananthshenoy03
2021-07-11 07:56
```ananthshenoy@ubuntu-HP:~/devhome/demopact/example-consumer$ npm t > consumer@0.1.0 test /home/ananthshenoy/devhome/demopact/example-consumer > cross-env CI=true react-scripts test sh: 1: cross-env: not found npm ERR! Test failed. See above for more details. npm WARN Local package.json exists, but node_modules missing, did you mean to install?```

matt.fellows
2021-07-11 08:08
Have you run npm install?

matt.fellows
2021-07-11 08:08
Also VS code is not a test framework, are you running from the terminal in VS code or via the run/debug features l?

ananthshenoy03
2021-07-11 09:21
Yes I have run npm install for which I got the following ```npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/react-scripts/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/jest-haste-map/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN react-scripts@3.4.4 requires a peer of typescript@^3.2.1 but none was installed. npm WARN sass-loader@8.0.2 requires a peer of node-sass@^4.0.0 but none was installed. npm WARN sass-loader@8.0.2 requires a peer of sass@^1.3.0 but none was installed. npm WARN sass-loader@8.0.2 requires a peer of fibers@>= 3.1.0 but none was installed. npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.14.5 requires a peer of @babel/core@^7.13.0 but none was installed. npm WARN @babel/plugin-proposal-class-static-block@7.14.5 requires a peer of @babel/core@^7.12.0 but none was installed. npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none was installed.```

ananthshenoy03
2021-07-11 09:21
Yes I'm running the commands via VS code Terminal

ananthshenoy03
2021-07-11 09:23
After running `npm install` I tried running the test `npm t` for which I got the following ```npm t > consumer@0.1.0 test /home/ananthshenoy/devhome/demopact/example-consumer > cross-env CI=true react-scripts test /home/ananthshenoy/devhome/demopact/example-consumer/node_modules/cross-env/src/index.js:23 ) ^ SyntaxError: Unexpected token ) at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:549:28) at Object.Module._extensions..js (module.js:586:10) at Module.load (module.js:494:32) at tryModuleLoad (module.js:453:12) at Function.Module._load (module.js:445:3) at Module.require (module.js:504:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/ananthshenoy/devhome/demopact/example-consumer/node_modules/cross-env/src/bin/cross-env.js:3:18) npm ERR! Test failed. See above for more details.```

ananthshenoy03
2021-07-11 09:25
I have cloned this demo project https://github.com/pactflow/example-provider into my local and trying to run the sample tests. Looks like I have some issue with installation set up could you guide me on this

matt.fellows
2021-07-11 11:42
what version of node are you running?

matt.fellows
2021-07-11 11:43
You can see the latest GH actions build is running, so the project definitely works: https://github.com/pactflow/example-provider/actions/runs/1013579203

matt.fellows
2021-07-11 11:43
have you made any changes to the project?

firstamit
2021-07-11 14:07
has joined #pact-js

omar554
2021-07-11 21:54
has joined #pact-js

k.deepupardha
2021-07-12 10:23
has joined #pact-js

ananthshenoy03
2021-07-12 10:45
I have following version installed ```@ubuntu-HP:~/devhome/demopact/example-consumer$ node -v``` `v6.17.1`

lumenofor
2021-07-12 10:46
has joined #pact-js

matt.fellows
2021-07-12 10:47
They are very old versions, we don't support 6 so I'm not surprised. Can you update?

matt.fellows
2021-07-12 10:48
It was EOL over 2 years ago

matt.fellows
2021-07-12 10:54
Another thing to note Ananth is that Pact is targeted at developers who have access to the code base and have familiarity writing unit tests

matt.fellows
2021-07-12 10:55
It's not a black box testing tool, so just bear that in mind - strong Dev knowledge of the language you are testing is recommended

ananthshenoy03
2021-07-12 11:55
Upgraded node version to latest `v16.4.2`and tried running the test using command `npm t` ```npm t > consumer@0.1.0 test > cross-env CI=true react-scripts test node:events:371 throw er; // Unhandled 'error' event ^ Error: spawn react-scripts ENOENT at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19) at onErrorNT (node:internal/child_process:480:16) at processTicksAndRejections (node:internal/process/task_queues:83:21) Emitted 'error' event on ChildProcess instance at: at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12) at onErrorNT (node:internal/child_process:480:16) at processTicksAndRejections (node:internal/process/task_queues:83:21) { errno: -2, code: 'ENOENT', syscall: 'spawn react-scripts', path: 'react-scripts', spawnargs: [ 'test' ] } ```

matt.fellows
2021-07-12 12:10
Have you tried removing node modules and reinstalling?

matt.fellows
2021-07-12 12:10
The previous install could be bogus given the old npm

dimundo
2021-07-12 13:13
hi! anyone encountered, that provider tests doesnt update pacts for broker from CI (works normally from local PC) ? consumer tests publishes new pacts from same build from CI

matt.fellows
2021-07-12 13:16
have you enabled publishing of verification results?


dimundo
2021-07-12 13:27
> http://process.env.CI !== undefined > true from logs

dimundo
2021-07-12 13:29
so, if i put explicitly true locally - it handles provider updates

dimundo
2021-07-12 13:49
and one more thing: with `user` account provider cant post verification - is this ok ? works in pact4s ( jvm/scala )

jayr.motta
2021-07-12 13:57
has joined #pact-js

dimundo
2021-07-12 14:21
and the answer is here

dimundo
2021-07-12 14:22
token remained from POC, which used token, and message was buried in DEBUG and having INFO logs nothing happened

doug.shattuck
2021-07-12 20:26
has joined #pact-js

matt.fellows
2021-07-12 22:06
What does that mean, sorry I don't understand the q

matt.fellows
2021-07-12 22:08
I'm incline to say "no" but I'm not quite sure :-)

matt.fellows
2021-07-12 22:17
Hmm I would have thought verification should failed with a rejected promise - are you sure you're not swallowing the exception?

tjones
2021-07-13 01:18
Also, could you share the log section where this error came up as DEBUG? I think it should be at least `WARN`

dimundo
2021-07-13 06:51
so, not much in logs, but warn appears with debug only ( maybe there is something like logback.xml in js ? )

dimundo
2021-07-13 06:56
not sure from where Thor came, but let it stay here

matt.fellows
2021-07-13 06:57
that?s definitely a bug if it?s not throwing an exception

matt.fellows
2021-07-13 06:57
I think pact-node tries to parse this output so perhaps that?s why it?s a `DEBUG` message. I?m surprised it doesn?t actually error though

dimundo
2021-07-13 06:58
maybe due pending ?

dimundo
2021-07-13 06:58
like ?failed? meh, whatever - its a pending one? :smile: havent dig into code still, so just some giggling/speculations

matt.fellows
2021-07-13 06:59
thanks

matt.fellows
2021-07-13 07:00
I hope not, but could be

matt.fellows
2021-07-13 07:00
Just raising an issue now


matt.fellows
2021-07-13 07:01
If you have more detail to add, that would be helpful

dimundo
2021-07-13 07:02
i have a feeling, that swallower promise could be the case

matt.fellows
2021-07-13 07:03
on your side or pact-node?

dimundo
2021-07-13 07:04
im not a js guru, so Promises sometimes makes me sad

dimundo
2021-07-13 07:04
does that looks ok ?

matt.fellows
2021-07-13 07:05
nah that looks OK, pretty sure it?s a problem in the Ruby process actually

matt.fellows
2021-07-13 07:05
```? YN0000: [2021-07-12 13:53:13.025 +0000] DEBUG (1219 on runner-uzumdsnp-project-10-concurrent-1gzcgn): pact-node@10.12.2: You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration. ? YN0000: Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?` in `Pact::ProviderVerifier::CLI::Verify````

matt.fellows
2021-07-13 07:06
It?s exiting with a `0` status code, so pact-node things it?s totally fine

dimundo
2021-07-13 07:06
but why Thor ?

dimundo
2021-07-13 07:06
its some Ruby internal joke ?

matt.fellows
2021-07-13 07:13
Thor is the CLI library it uses


dimundo
2021-07-13 07:16
ah, thought is Tor not Thor, but its Thor

matt.fellows
2021-07-13 07:17
:smile:

sorin_balbae
2021-07-13 07:41
has joined #pact-js

akara
2021-07-13 10:34
has joined #pact-js

nathan.derave
2021-07-13 12:28
has joined #pact-js

matthew.schaad
2021-07-13 21:29
has joined #pact-js

neenad.jadhavgre
2021-07-13 22:30
has joined #pact-js

neenad.jadhavgre
2021-07-13 22:43
Hello there, I am trying to implement Provider tests for a bff service and I wanted to take a look at some examples where the provider response is mocked instead of calling the real services.

matt.fellows
2021-07-13 22:48
Do you mean mocking downstream services of the provider you're testing?


cristian
2021-07-14 06:18
has joined #pact-js

michal.bernhard
2021-07-14 11:16
has joined #pact-js

dawoud.sheraz
2021-07-14 11:38
Hi. Does anyone here have any experience writing consumer tests in a codebase that uses axios-mock-adapter to mock some HTTP operations? In the code that I am working with, there is a wrapper layer responsible for making api calls. The client within the wrapper is mocked via axios-mock-adapter and it seems to be messing with pact-js operations.

koradrop
2021-07-14 13:06
has joined #pact-js

robert.strehli
2021-07-14 13:32
has joined #pact-js

neenad.jadhavgre
2021-07-14 14:15
Yes thank you, this is exactly what I need, but having some examples where this kind of stubbing is implemented would be great.

pedroefajardo_pactio
2021-07-14 17:11
for these two steps: ```1) Set up a state change endpoint in your provider 2) Start the provider with these state change endpoint included``` i understand the why, i don?t understand how it works. say, I: ? Add an endpoint to the provider, how and who passes the expected state handler values? now on the provider side, in the endpoint for Pact, are the expected values received and then what? ? How do I use these values in the provider side when the consumer tests run?

richard.jones254
2021-07-14 23:53
has joined #pact-js

edanielsen
2021-07-15 00:46
has joined #pact-js

abatan.k
2021-07-15 03:48
has joined #pact-js

tjones
2021-07-15 04:11
Pact obviates the need to mock in this way

tjones
2021-07-15 04:12
Mocks for the axios layer mean that you're "marking your own exam", in that you don't know if the mock aligns with the actual provider

tjones
2021-07-15 04:13
A Pact contract is like a mock that you can replay against the provider.

tjones
2021-07-15 04:13
So you would replace the Axios mocks with a pact mock.

mandeep302755
2021-07-15 04:49
has joined #pact-js

mahajanrupali22
2021-07-15 05:46
has joined #pact-js

dawoud.sheraz
2021-07-15 05:51
hmm, that is a tough scenario. The axios mock is for mocking the client and its auth service.

matt.fellows
2021-07-15 10:33
Why are you mocking the client in a pact test? Usually, that's the exact thing you want to unit test (and therefore not mock)

matt.fellows
2021-07-15 10:33
If you need to mock downstream auth, you can do that with pact (or stub it out of it's a separate service, and have a separate pact test to cover that)

matt.fellows
2021-07-15 10:34
What do you use for stubbing now?

matt.fellows
2021-07-15 10:34
Tools like Jest, Sinon etc are pretty standard

dawoud.sheraz
2021-07-15 11:47
So the flow that is happening is like `getCustomClient().get/post/put` . The custom client contains user information and acts as a layer for making api calls with axios. For unit tests, the client information is mocked via a MockAuth service. What I am trying to test via pact is the actual api calls(get/post/put etc.), so I am only adding interactions for that. Since underlying client has some details too, I am not sure if mocking them with pact is the right answer here. Please correct me if I am wrong/missed some context. Thanks

hylke.de.jong
2021-07-15 12:49
has joined #pact-js

efemgy
2021-07-15 14:27
has joined #pact-js

crazycabo350
2021-07-15 18:17
has joined #pact-js

matt.fellows
2021-07-15 23:25
As in, `getCustomClient` makes three calls, and only one of them needs to be mocked by Pact?

matt.fellows
2021-07-15 23:25
Perhaps axios mock adapter isn?t the ideal use here, and other stubbing tools could be used?

matt.fellows
2021-07-15 23:26
But also, from memory, axios mock adapter let?s you configure which calls to stub, so presumably you could exclude the ones that goto Pact

amreenshaik.basha
2021-07-16 04:06
has joined #pact-js

rhian.van.esch
2021-07-16 12:14
has joined #pact-js

wilco.van.esch
2021-07-16 12:30
has joined #pact-js

karl.morrison
2021-07-16 12:56
has joined #pact-js

timothyjabez
2021-07-16 17:23
has joined #pact-js

abatan.k
2021-07-16 18:37
Hello, i am a little bit lost with pact un JS world. I am confuse about which way to go when publishing and checking if we can deploy. In the docs, I see that we wrote a publish-contracts.js file , but to check if we can deploy, we use a docker image. Can we create a script in JS for checking if we can deploy ? I would like to be able to use two command for publishing & check deploy like that: `yarn pact:publish` => `ts-node publish-contracts.ts` `yarn pact:can-ideploy` => `ts-node can-i-deploy.ts`

abatan.k
2021-07-16 20:13
I wanted to delete the message, since i found the class `CanDeploy` on the package `@pact-foundation/pact-node` , but i can't :sweat_smile:

matt.fellows
2021-07-16 22:26
I'd recommend using the CLI for both activities. It's bundled into the JS package already

matt.fellows
2021-07-16 22:26
Personally I don't use the JS interface for publishing / can-i-deploy

abatan.k
2021-07-16 23:14
oh, i did not see the binaries `pact-broker` in the node_modules, did i miss it on the docs ??

matt.fellows
2021-07-16 23:22
It's documented somewhere but probably not very obvious

matt.fellows
2021-07-16 23:22
You could use `npx pact-broker`

matt.fellows
2021-07-16 23:22
That's what I do, and I should update the examples to do also

abatan.k
2021-07-16 23:33
yes, i found it, i will use it then, thx for your help :slightly_smiling_face:

tjones
2021-07-17 03:13
@abatan.k In general, you should only need to use things from pact-node directly if you are writing tooling for pact. Is there somewhere the documentation needs improving?

abatan.k
2021-07-17 19:39
Hello, i would like to know if it's possible to use a matcher for the status code. (I'm using jest-pact) My first interaction use a Matcher like this one: ```willRespondWith: { status: Matchers.regex({ generate: '200', matcher: '[200-299]', }), },``` My second interaction uses a Matcher like this one: ```willRespondWith: { status: Matchers.regex({ generate: '0', matcher: '0|[^200-299]', }), },``` Is that legit or is there any matcher to perform a range check on a status code ??

abatan.k
2021-07-17 19:52
@tjones I think that the doc may be improve indeed. At first glance, when i look at the documentation, on js side, i'm a little bit confuse. If i'm a node developer, i prefer to manage every related test and other tools for testing with some script from package.json. But in the doc, the examples for nodejs, are using docker and a Makefile. Which, imo, are mostly interesting for devops in an organization. But for a single JS developer, he/she would rather use what he/she knows, that means a simple call to `npx pact:publish` which translate to `npx pact-broker publish ...` I think that the same things go for a PHP developer, who prefer to use a command with `composer` to publish and check if he can deploy. All i say, is that to bring down the barrier level when discovering Pact, you should propose to use tools that developers of specific language and environment are used to. And show how in the docs :slightly_smiling_face:

matt.fellows
2021-07-17 22:21
It's not available yet but coming in the next major Pact version

matt.fellows
2021-07-17 22:21
At the moment you need to be specific

abatan.k
2021-07-17 23:22
nice to know, do you have roadmap accessible ? :slightly_smiling_face:

matt.fellows
2021-07-18 02:38
There are kind of a few. We use https://pact.canny.io/ to drive features across the framework, and https://github.com/pact-foundation/pact-specification/tree/version-4 (that?s the latest version) to drive framework level (essentially, what the pact file structure is) changes

tjones
2021-07-18 08:18
As Matt says, at the moment it's not possible to do this. A couple of things to keep in mind though: * In general, you want to only specify what your client needs. So, you don't have to enumerate the whole API (sometimes people try to do this). * However, sometimes you don't care about the content, just that there was a 2XX. Unfortunately, at the moment you'll need to know whether your provider returns a 200 or a 204.

tjones
2021-07-18 08:18
Also, I don't think status 0 is valid. Is your provider really returning that?

tjones
2021-07-18 08:20
A quick google search suggests that status 0 is returned from a few different request libraries, but it seems unlikely that a server is really returning that

abatan.k
2021-07-18 08:21
yes exactly

abatan.k
2021-07-18 08:21
it is returned usually by request librairies

tjones
2021-07-18 08:21
> But in the doc, the examples for nodejs, are using docker and a Makefile. Which example is this?

tjones
2021-07-18 08:22
As far as I am aware, none of the pact-js examples use makefiles



tjones
2021-07-18 08:22
Oh, that's a Pactflow example. I don't know anything about that.


tjones
2021-07-18 08:23
^ @matt.fellows

abatan.k
2021-07-18 08:23
it's not a problem though :wink:

abatan.k
2021-07-18 08:24
i get this status code when the url is not specified, and in my case, the consumer is for the client, and i suppose that any request without 2xx status code is a failed one (from the viewpoint of the user :slightly_smiling_face:)

tjones
2021-07-18 08:25
Thanks. That's part of the Pactflow documentation, I'm afraid - which is outside the Pact OSS sphere. I personally think it's confusing for Pactflow to have their own examples of how to use Pact

tjones
2021-07-18 08:26
@matt.fellows, I think this is another strike in favour of moving the pactflow examples into the main repo.

abatan.k
2021-07-18 08:27
well most of new user of pact (and solo dev) will use pactflow instead of hosting personal pact-broker

abatan.k
2021-07-18 08:28
when i discovered pact, i though that pactflow and pact was the nearly the same thing (or very closely related)

abatan.k
2021-07-18 08:28
like npm and node

tjones
2021-07-18 08:28
Yes, but pactflow is a different entity. I don't work for them, I'm an open source maintainer.

abatan.k
2021-07-18 08:28
oh ok :slightly_smiling_face:

tjones
2021-07-18 08:28
Yes, I agree that this is confusing. I'd really like to clear that up.

tjones
2021-07-18 08:28
I think we can be better at making it clear that there's a difference

tjones
2021-07-18 08:29
and I'd like to see more use of the open source examples (or at least a `examples/pactflow`) in the pactflow documentation.

tjones
2021-07-18 08:31
> If i'm a node developer, i prefer to manage every related test and other tools for testing with some script from package.json. Yes, 100%. After the Pact spec V3 release for Pact-JS I plan to tackle the config issue: https://github.com/pact-foundation/pact-js/issues/602 This will make it much easier to use scripts in package.json

tjones
2021-07-18 08:32
It's possible at the moment - for example, here's a line from one of my personal projects: ``` "pact:publish": "pact-broker publish pacts --consumer-app-version=\"$(absolute-version-from-git-tag)\" --broker-base-url=https://tjones.pact.dius.com.au/ --broker-token=\"$TJONES_PACT_CI_TOKEN\""```

abatan.k
2021-07-18 08:32
In the https://github.com/pact-foundation/pact-js/tree/master/examples/jest you use a publish.js file, which was the thing that lead me to using JS Classes to implement publishing & can-i-deploy :slightly_smiling_face:

tjones
2021-07-18 08:32
Yes. That's a pattern I would really like to remove

tjones
2021-07-18 08:33
I'll make an issue for it

abatan.k
2021-07-18 08:33
Anyway, i see that in the Node documentation, you use the binaries from node_modules, so i guess it's ok :slightly_smiling_face:


tjones
2021-07-18 08:38
> Anyway, i see that in the Node documentation, you use the binaries from node_modules, I'm not sure it's very clear, though. For example, this in the documentation still uses `pact-node` directly: https://github.com/pact-foundation/pact-js#publishing-pacts-to-a-broker

tjones
2021-07-18 08:39
definitely something we should fix

tjones
2021-07-18 08:39
where in the docs are you seeing using the binstubs?


tjones
2021-07-18 08:41
Ah, amazing! I'll link that to the issue

tjones
2021-07-18 08:41
thank you

abatan.k
2021-07-18 08:41
i get there by clicking on _*Complete Example (Node env)*_ on this page https://docs.pact.io/implementation_guides/javascript

tjones
2021-07-18 08:41
I'd really like to update all the examples so they all showcase the same features, too

tjones
2021-07-18 08:41
Thank you!

tjones
2021-07-18 08:42
That example still uses `publish.js` though. So it's a bit of a hybrid

abatan.k
2021-07-18 08:42
your welcome, thx to you to maintain a good project like this one :slightly_smiling_face: it's a pleasure to do contract testing with pact :slightly_smiling_face:

tjones
2021-07-18 08:46
Thank you! You're very welcome, and I'm glad it's a useful tool! I think the pactflow initiative is a very good one (and I use it myself, as you can see from my example), but there are a few places where the concerns have leaked between documentation / examples etc.

tjones
2021-07-18 08:48
So, the pact mock is setting up the actual interaction which will be returned from the actual (mock) server. I suspect that if you want to test the case of incorrect config returning 0 from your framework, then you'll need to do a test that isn't a pact test.

abatan.k
2021-07-18 08:49
ok, i was thinking about that :slightly_smiling_face: thx for the insight :wink:

tjones
2021-07-18 08:49
Letting us know where the confusing bits are is really really useful!

abatan.k
2021-07-18 08:50
yes, of course, and it seems like pact is slowly migrating to v3, so it can ben difficult to maintain perfect documentation :slightly_smiling_face:

matt.fellows
2021-07-18 11:20
Thanks Carere, that?s helpful

matt.fellows
2021-07-18 11:21
@tjones not sure I?m following this: > and I?d like to see more use of the open source examples (or at least a `examples/pactflow`) in the pactflow documentation. I think we?re all agreed of trying to merge the documentation in some form, but I don?t know what you mean by ?more use of the open source examples in the pactflow documentation??

matt.fellows
2021-07-18 11:21
As Tim has said, we?re working on making the difference between Pact and Pactflow clearer

tjones
2021-07-18 11:38
I mean, I'm still not clear on why there are examples of how to use pact-js hosted under the pactflow github

tjones
2021-07-18 11:39
there's a react example there, which I would love to have under the main repo

matt.fellows
2021-07-18 11:41
They are examples of how to use Pact with Pactflow

matt.fellows
2021-07-18 11:41
they are also designed to be mixed and matched with the CI/CD workshop

matt.fellows
2021-07-18 11:42
(hence the Makefile)

matt.fellows
2021-07-18 11:42
Lastly, I use them in sales demos. Having them in one place is helpful for customers/prospects after a call

matt.fellows
2021-07-18 11:42
If we had a single combined set of documentation, I think we could make this work though in a non-confusinsg way

matt.fellows
2021-07-18 11:43
It?s kind of a catch 22.

matt.fellows
2021-07-18 11:43
If we had examples that used Pactflow in our OSS repos, that would further blur the lines (that I guess we?re trying to avoid)

matt.fellows
2021-07-18 11:43
but that wouldn?t be helpful to our Pactflow customers, who want clear examples of how to integrate it into their systems

matt.fellows
2021-07-18 11:45
I don?t really want to be creating another island of information, but the reality is we need documentation that makes it easy for Pactflow customers to work with Pact

matt.fellows
2021-07-18 11:46
My vote is still have all of the Pact + Pactflow documentation at http://docs.pact.io and then make the line less blurry.

matt.fellows
2021-07-18 11:46
I think https://docs.cypress.io/ do it well

matt.fellows
2021-07-18 11:46
(The ?Dashboard? is the commercial bit)

github2
2021-07-18 12:20
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.43_ published by github-actions[bot]

tjones
2021-07-18 12:43
> If we had examples that used Pactflow in our OSS repos, that would further blur the lines I guess my thinking is that it would make the lines clearer, because there would be less "how does Pact work" in Pactflow. Especially as the major difference in the pactflow examples is the use of the broker token.

tjones
2021-07-18 12:44
New users don't know (or care) there's a difference between Pact and Pactflow, but we can help people learn by teaching / showing examples of Pact in OSS land, and having the Pactflow specific stuff only over in Pactflow.

tjones
2021-07-18 12:44
I know I'm a broken record on this. Sorry.

tjones
2021-07-18 12:50
I think it will be less confusing with all the examples in one place.

ppdnguyen
2021-07-18 16:23
has joined #pact-js

cgoodison
2021-07-18 23:56
has joined #pact-js

ivo.velthoven174
2021-07-19 12:13
Hi! Is it just me or is `consumerVersionTags` and `consumerVersionSelectors` `VerifierV3Options` just not working in v3?

sripathi
2021-07-19 12:30
has joined #pact-js

pedroefajardo_pactio
2021-07-19 14:02
good morning I am trying to understand the relationship between a consumer state via addInteraction.state and a Provider?s state via state handlers I create some consumer tests in JavaScript where I add a state via: ```provider.addInteraction({ state: 'product with ID 10 exists', ...``` I have a provider written in a language that is not natively supported by http://Pact.io so: ? Added two endpoints, a POST and a GET. I am hoping to call these via `--provider-states-setup-url` and `--provider_states_url` using the `pact-cli` Questions: ? How does running the verifier exercise the provider states? How does it associate a test with state `1` with a provider state handler `1` on a provider that is written in a language that Pact does not support natively? ? Does it get the expected state from the Pact file and injects it (the state) into the test via the url mentioned above? Does it call the POST before the test with a given expectation is run and then it calls the GETter when the test is run? ? How are `stateHandlers` implemented on the Provider side for a provider written on a language not supported by Pact? ? How does the actual verification work if the expected state is being injected? ? Say the provider state, as defined by the consumer, injects state { ?name?:?pact? } for a state on `get/:userId` but the provider is now returning {?firstName?:?pact?}. Since Pact is injecting the state defined by the consumer test how does it fail the test because the actual implementation of the provider is now returning something different?

matt.fellows
2021-07-19 14:17
I just saw your issue. I'll take a look tomorrow. Can you please show your code example with that bug request too?

matt.fellows
2021-07-19 14:18
The trace definitely shows no tags passing thru to the broker, so there is definitely an issue or invalid config (which probably means a bug if it got that far)

ivo.velthoven174
2021-07-19 14:18
I found the issue in the code!

ivo.velthoven174
2021-07-19 14:18
In the rust native code

ivo.velthoven174
2021-07-19 14:19
.

ivo.velthoven174
2021-07-19 14:22
I'll make a PR otherwise, then you can look at it later and make necessary changes. :slightly_smiling_face:


ivo.velthoven174
2021-07-19 15:13
If you can also look at: https://github.com/pact-foundation/pact-js/pull/712 :slightly_smiling_face: would be great!

calvin.krist
2021-07-19 15:29
has joined #pact-js

vinay.viswanadha
2021-07-19 15:30
has joined #pact-js

brian.mitchell
2021-07-19 15:37
has joined #pact-js

pedroefajardo_pactio
2021-07-19 16:05
I found a link for the Lifecycle of a provider verification at https://github.com/pact-foundation/pact-go#lifecycle-of-a-provider-verification I *think* that answers the question of what gets called when but i still have knowledge gaps on how the request filter (pre) and request filter (post) work. I can?t seem to find documentation with examples about the Pact functions, API documentation, in a single place. Maybe I am looking in the wrong place.

mike.geeves064
2021-07-19 18:07
has joined #pact-js

tjones
2021-07-20 01:56
> I can?t seem to find documentation with examples about the Pact functions, API documentation, in a single place. http://docs.pact.io is the core documentation. That pulls in the readmes from the different frameworks

tjones
2021-07-20 01:59
> How does running the verifier exercise the provider states? If you give a state change URL to the verifier, it sends an http request to the state change URL with the state string in the payload.

tjones
2021-07-20 02:01
If it's a V2 pact, the format is a POST request with the payload: ```{ states: [/* state strings*/] }```

tjones
2021-07-20 02:02
You're right that I don't think this is documented obviously (though I think it is documented somewhere). We should fix that.

tjones
2021-07-20 02:03
> Does it call the POST before the test with a given expectation is run and then it calls the GETter when the test is run? Yes, it calls the POST before the test is run. As far as I am aware, there's is no GET call.

tjones
2021-07-20 02:03
> How are stateHandlers implemented on the Provider side for a provider written on a language not supported by Pact? You use a state change endpoint as above.

tjones
2021-07-20 02:52
> How does the actual verification work if the expected state is being injected? I don't think I understand this question, I'm afraid.

tjones
2021-07-20 02:52
With variables injected from the provider, they come as a map in part of the V3 state setup URL

ben.clare2
2021-07-20 08:16
has joined #pact-js

rafael.moral
2021-07-20 11:48
has joined #pact-js

andrii.rakhimov
2021-07-20 23:06
has joined #pact-js

andrii.rakhimov
2021-07-20 23:11
qq: How do you run one particular test with pact? Currently when I pass any argument with `yarn pact:run` it runs all available pact tests in the repo.

boris.gordon
2021-07-20 23:25
has joined #pact-js

matt.fellows
2021-07-20 23:30
Is this on the consumer or provider side?

matt.fellows
2021-07-20 23:30
On the consumer side, it?s just whatever test framework yiou use

matt.fellows
2021-07-20 23:30
if you have an `it('?.', () => {})` then most support `it.only`

pedroefajardo_pactio
2021-07-22 02:39
ok. The pact tests are now running but failing, which is progress. I am using the Dockerized version of the pact-cli the on state for the one test I have so far is being passed into the provider and now what do I do? How do I use the values being injected? I am to store them in a variable and then what? I am looking for examples on how and what to do. I appreciate your help

tjones
2021-07-22 04:25
To use the states, you need to set up a state handler URL on your service that can be started when the provider is spun up for verification. What that state handler does is up to the architecture you have. Usually a repository is stubbed or populated in the state handler.

github2
2021-07-22 06:35
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.44_ published by github-actions[bot]

matt.fellows
2021-07-22 06:53
@ivo.velthoven174 :point_up: thanks and :taco: !

matt.fellows
2021-07-22 06:54
We can get a separate release out for the relative imports when that is merged. Tim seems to be across it, so will leave that for the two of you

tjones
2021-07-22 11:35
Oh! I'm not really across it- I haven't had the chance to look yet. I just want to understand why the types changed in that example, because as I understand it so far, they shouldn't have. My theory is that we made a mistake in the past that is somehow uncovered in this situation.

tjones
2021-07-22 11:35
Probably merging it in and finding out afterwards is ok, since we're still in beta.

ryn.anderson
2021-07-22 17:41
has joined #pact-js

pedroefajardo_pactio
2021-07-22 17:57
forgive me for not understanding the purpose of the state handler. ? If a test passes its expected state; and ? if we are supposed to for example, stub the repository, or populate it in the state handler with the data (state) being passed by the state in preparation for when the test runs. Then what is the advantage of using Pact? Or rather how will Pact know something is different between what the actual Provider is returning if the data that?s being returned is the data that was passed by the test?

pedroefajardo_pactio
2021-07-22 18:44
oh, i think i see maybe, I am supposed to seed the db of the app with the state info passed in so that when the test calls the data is in the db and if for any reason the app has changed the way objects are returned from the endpoint under test then there will be a difference between what?s in the Pact in the broker and what the the app is returning. maybe that?s ^^^^^ how this is supposed to work

schakalabbi
2021-07-22 21:29
has joined #pact-js

tjones
2021-07-23 00:02
Yes, your second example is a better way of thinking about it

tjones
2021-07-23 00:03
the state handler is never "under test". Your state handler is called to set up the state that the interaction requires

tjones
2021-07-23 00:03
Pact is for testing the communication boundary

tjones
2021-07-23 00:04
See the diagrams here to get a clear picture: https://docs.pact.io/getting_started/how_pact_works

uryadov212
2021-07-23 06:21
@uryadov212 has left the channel

consulting
2021-07-23 12:33
has joined #pact-js

pedroefajardo_pactio
2021-07-23 13:27
thanks for your replies.

consulting
2021-07-23 13:33
Hi everybody! I'm new to Contract Testing :slightly_smiling_face: I've been able to make Pact work with Angular using Karma Pact. I'm still having a weird behavior though... and I can't figure it out (even after dissecting every tutorial and example I could put my hand on!) It seems that when I launch "ng test", two instances of the Pact Server are started. Important note: I have only one test (to keep things simple) and it seems to be ran twice: ```$ ng test [2021-07-23 12:42:42.582 +0000] INFO (5112 on ULTIMATE-DROU): pact-node@10.12.2: Creating Pact Server with options: {"cors":true,"spec":2,"port":44332,"consumer":"angular-ui","provider":"weatherforecast","logLevel":"DEBUG","log":"D:\\workspaces\\weather-app\\logs\\pact.log","dir":"D:\\workspaces\\weather-app\\pacts","pactFileWriteMode":"overwrite","ssl":false,"host":"localhost"} [2021-07-23 12:42:42.585 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: Starting pact binary 'standalone\win32-1.88.49\pact\bin\pact-mock-service.bat', with arguments [service --cors true --pact_specification_version 2 --port 44332 --consumer angular-ui --provider weatherforecast --log-level DEBUG --log D:\workspaces\weather-app\logs\pact.log --pact_dir D:\workspaces\weather-app\pacts --pact-file-write-mode overwrite --host localhost] [2021-07-23 12:42:42.590 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: Created 'standalone\win32-1.88.49\pact\bin\pact-mock-service.bat' process with PID: 24380 [2021-07-23 12:42:43.137 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [i386-mingw32] [2021-07-23 12:42:43.139 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: INFO WEBrick::HTTPServer#start: pid=26184 port=44332 23 07 2021 08:42:43.629:INFO [pact]: Pact Mock Server running on port: 44332 23 07 2021 08:42:45.315:INFO [karma-server]: Karma v4.3.0 server started at http://0.0.0.0:9876/ 23 07 2021 08:42:45.315:INFO [launcher]: Launching browsers Chrome with concurrency unlimited 23 07 2021 08:42:45.321:INFO [launcher]: Starting browser Chrome 23 07 2021 08:42:48.110:INFO [Chrome 91.0.4472 (Windows 10.0.0)]: Connected on socket BWIFZ4wuaf-PNBtlAAAA with id 7045608 INFO: 'Setting up Pact using mock service on port: "44332"' Chrome 91.0.4472 (Windows 10.0.0): Executed 0 of 1 SUCCESS (0 secs / 0 secs) Chrome 91.0.4472 (Windows 10.0.0): Executed 1 of 1 SUCCESS (0.205 secs / 0.113 secs) TOTAL: 1 SUCCESS TOTAL: 1 SUCCESS [2021-07-23 12:42:49.649 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:7 D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread' ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:6 D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread' [2021-07-23 12:42:49.763 +0000] INFO (5112 on ULTIMATE-DROU): pact-node@10.12.2: Removing all Pact servers. [2021-07-23 12:42:49.763 +0000] INFO (5112 on ULTIMATE-DROU): pact-node@10.12.2: Removing Pact process with PID: 24380``` Here's my karma.conf.js (the pact setup excerpt), with a single provider defined ```pact: [{ //When I use cors: true, it creates a double connection... cors: true, //ssl: true, //Version of the Pact json file that will be generated spec: 2, //This port needs to be aligned with the port we use in the angular service to call the API port: 44332, //So far, consumer can be set to anything... consumer: "angular-ui", //This context name has to be the name of the real API context name provider: "weatherforecast", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }]``` And finally, my pact test: ```import {TestBed} from '@angular/core/testing'; import {HttpClientModule} from '@angular/common/http'; import {PactWeb, Matchers} from '@pact-foundation/pact-web'; import { WeatherService } from './weather.service'; import { Weatherforecast } from './weatherForecast'; import * as path from 'path'; describe('WeatherServicePact', () => { var provider; // Setup Pact mock server for this service beforeAll(() => { provider = new PactWeb({ port: 44332, host: 'localhost', }); // Required if run with `singleRun: false` provider.removeInteractions() });```


matt.fellows
2021-07-23 13:46
I can?t understand why two servers wousld be started though

matt.fellows
2021-07-23 13:47
what do you mean by ?double connection??

matt.fellows
2021-07-23 13:47
(also it?s late here, but saw this so thought I could ask some questions)

consulting
2021-07-23 14:04
What I see in the console output is doubled... so I assumed that it was called twice, probably by two different Pact Server. ```Chrome 91.0.4472 (Windows 10.0.0): Executed 0 of 1 SUCCESS (0 secs / 0 secs) Chrome 91.0.4472 (Windows 10.0.0): Executed 1 of 1 SUCCESS (0.205 secs / 0.113 secs) TOTAL: 1 SUCCESS TOTAL: 1 SUCCESS```

consulting
2021-07-23 14:07
When I look at the console output of the tutorials I ran into, they never have doubles like that.

galante2123
2021-07-23 14:14
has joined #pact-js

consulting
2021-07-23 14:34
yeah... it's just an assumption from my part (still juggling with the concepts... it's probably not the server but the providers that are duplicated). It just feels like the Pact Provider configured in the karma config file and the one in the test file are creating this situation... In the Karma & Jasmine example on Pact-JS GitHub, PactWeb is instantiated with no options (hence using the default 127.0.0.1:1234). I tried to align with that code and config as much as possible in prior attempts to make this work, but I never managed to understand the imports required to be able to instantiate PactWeb as a class defined in Pact like seen in the example: "new Pact.PactWeb".

consulting
2021-07-23 14:37
Wow, I just saw that you are located in Melbourne :slightly_smiling_face: Thanks for taking the time! This is not urgent... we can continue the conversation on monday! I'm working on a POC for one of my client... I've heard about Pact a few years ago, but never got time to experiment it myself :slightly_smiling_face:

dc113604
2021-07-23 14:39
has joined #pact-js


matt.fellows
2021-07-23 22:58
That's does look strange. Are you sure there's no extra process configured to start? Any chance you could share your repo or a reproducible example?

matt.fellows
2021-07-23 22:58
FWIW we are wanting to get rid of pact web entirely going forward


matt.fellows
2021-07-23 23:00
TL;DR can you test using a node based tool like Jest/mocha ?

matt.fellows
2021-07-23 23:00
All good! We're used to the world getting busy when we're going down :rolling_on_the_floor_laughing:

tjones
2021-07-25 02:49
You're welcome! Let us know if you have any further questions.

pedroefajardo_pactio
2021-07-25 03:35
thank you

dsinecos
2021-07-26 04:49
has joined #pact-js

mebenhoeh
2021-07-26 05:20
has joined #pact-js

consulting
2021-07-26 07:39
Thanks for all this information! (I was camping this weekend, hence the delay)

matt.fellows
2021-07-26 07:42
no worries, hope it was fun!

consulting
2021-07-26 07:43
I'll look into your alternatives (Jest and Mocha) :slightly_smiling_face: Not being integrated in Karma is not a big deal for me because on most project I worked where Angular was involved, Node was also around). I'll have to ask around and see if that's a problem for them (I'm fairly new to the company)

matt.fellows
2021-07-26 07:45
yeah, I?ve noticed Angular people tend to be pretty keen on staying in the Jasmine/Protractor/Karma (whatever it is these days) env

matt.fellows
2021-07-26 07:45
But honestly, not sure how we?re going to make it work with the latest version of Pact

consulting
2021-07-26 07:46
I mean, I love having that Karma deamon running in the background keeping me honest with having the green bar :slightly_smiling_face:

consulting
2021-07-26 07:47
Angular still very popular... are you aware if people have found other alternatives?

consulting
2021-07-26 08:18
I red the full post you referenced up there... and the suggestion from the team. I tried to use Pact-JS only, doing the setup and finalize by hand but when run using ng test (ultimately Karma), it was complaining that I was missing a bunch of properties on a Browser option (which could be set in the packages.json file)... fixing one would make me stumble on another one :smile:

consulting
2021-07-26 08:26
so my understanding is that even if I don't use Karma-pact and pact-web, and I try to manage the pact server myself, it will still be a problem if I run the test with Angular's default test runner. If that's about right, then I see three options: ? Continue to try to run Pact-JS in Angular with Karma as a test runner (because I was possibly almost there?!) ? Or I could try to run my Angular service in a test suite implemented in Mocha or Jest, injecting my dependancies by hand (or maybe the TestBed would still work... I have no clue.. it's too late / early for me :slightly_smiling_face:) ? Or delegate to a BFF (in Node, Java or some other language supported by Pact) to then be able to test the integration

consulting
2021-07-26 08:27
I'll try to catch some sleep, but I would love to hear your thoughts later :slightly_smiling_face: Thanks again for your precious feedback!

consulting
2021-07-26 14:00
I'm trying to figure out why people using React don't seem to have the same problem? (Unfortunately, I never used React, being a fan of Angular since early 2010!)

matt.fellows
2021-07-26 14:15
React tests run in node, which has access to the filesystem

matt.fellows
2021-07-26 14:15
Karma runs out of node, so it cannot for e.f. start a server so the interface needs to be decoupled from the server

matt.fellows
2021-07-26 14:17
> > Or I could try to run my Angular service in a test suite implemented in Mocha or Jest, injecting my dependancies by hand (or maybe the TestBed would still work... I have no clue.. it's

matt.fellows
2021-07-26 14:17
That's what I'm suggesting

matt.fellows
2021-07-26 14:18
You can do it as per the examples, it just seems like there is an issue

matt.fellows
2021-07-26 14:18
But long term it's probably going to go as an option

matt.fellows
2021-07-26 14:19
Not sure if this is helpful? https://github.com/niklas-wortmann/ngx-pact

dsmileb
2021-07-26 16:06
has joined #pact-js

consulting
2021-07-26 16:12
Thanks for all your feedback Matt! If I can make this work, I'll try to contribute something in the form of a tutorial or a podcast :slightly_smiling_face:

hazel.wright
2021-07-26 19:04
has joined #pact-js

matt682
2021-07-27 01:32
has joined #pact-js

tjones
2021-07-27 04:55
`TestBed` will still work, although to be honest, I don't really know why you'd need it for a consumer test


tjones
2021-07-27 04:56
(it's not exactly angular, but nestjs uses a lot of patterns from angular, as I understand it)

tjones
2021-07-27 04:57
> If I can make this work, I'll try to contribute something in the form of a tutorial or a podcast :slightly_smiling_face: Yes please!! It would be awesome if we could have some angular examples in the `examples` folder. This is a common question, and I'm not really an angular person

tjones
2021-07-27 04:57
happy to help out if you need

dawoud.sheraz
2021-07-27 11:25
For the sake of update, axios mock adapter mocking was intervening with pact-js mocking. Once I tried without axios mock adapter, the pact mock server was hit by the client. Although now I am seeing network error/CORS issue. The pact logs now show the interaction has been hit, which was not happening previously.

matt.fellows
2021-07-27 11:45
You should be able to disable your HTTP client from sending CORS requests on non browser environments, pact also has a CORS flag you can enable to respond to cors requests

consulting
2021-07-27 12:42
Thanks Timothy! I'm not too worried about the TestBed... it's a nice to have. I've been busy in meeting most of my time yesterday, so I didn't progress much... :disappointed: It seems that Mocha has not made it's way into Angular's fan heart lol There are 1 or 2 decent ressource and they use Webpack, which I'm not familliar with. There seems to be more people using Jest than Mocha with Angular... I might try that way if I can't succeed with Mocha. Right now, when I try to run my pact test, it says that it "can't use import statement outside a module" (Angular side problem). Angular seems to need some form/part of DOM to be able to launch properly, which seems to be fixed using jsdom... that's my next target :slightly_smiling_face:

matt.fellows
2021-07-27 12:49
Yeah I think Jest is the hipster kid on the block, mocha was more the first popular node based one (after Jasmine, which is what Karma uses from memory)

matt.fellows
2021-07-27 12:51
sounds like you?re on the right track

consulting
2021-07-27 13:01
yes you are right, Karma uses Jasmine. I went straight to Mocha to save time (I thought lol) because I've used it with Node in the past.

consulting
2021-07-27 15:35
Almost there! I fix most of the issues... I'm stuck with mocha not being able to see my Angular service (custom dev, not internal). All other imports are working.

consulting
2021-07-27 15:37
I had those before when I was missing thirdparty dependencies... but now that it's a local service that I created, I'm mystified :slightly_smiling_face: So close!

nathan.derave
2021-07-27 16:34
Hey there ! I?m having some issues to figure out how to define the Pact specification of nested payloads. I?m not 100% clear of when to use `like` in conjunction with `eachLike` etc. Here is an example payload that should be legit: ```const expected = { id: 'cc812d76-b5af-4a1b-a7be-e63115e19bbd', recommendations: [{ is_external: false, list_position: 0, rankings: [{ brands: ['pzc', 'abcd'], image_url: 'https://something.com'}), followable: { followed: true, id: 'article_location_abcd', stats: { df: 12636.0, idf: 6.05343245, n_recent_articles: 59.0}, display_forms: [{ language: 'nl', text: 'Verinigd Koninkrijk'}, {...}]}, {...}]}, {...}] }``` Some observations about the example payload above: ? `recommendations` is a list of complex objects ? `rankings` as well (and is part of one `recommendation`) ? `display_forms` is also a list (and is part of one `ranking`) Hence, here is my Pact specification of the expected payload: ```const expected = { id: like('cc812d76-b5af-4a1b-a7be-e63115e19bbd'), recommendations: eachLike({ is_external: false, list_position: 0, rankings: eachLike({ brands: eachLike('pzc'), image_url: 'https://something.com'}), followable: { followed: true, id: 'article_location_abcd', stats: { df: 12636.0, idf: 6.05343245, n_recent_articles: 59.0}, display_forms: eachLike({ language: 'nl', text: 'Verinigd Koninkrijk'}) } }) }``` The problem is that, when I verify the Pact on the provider side, some errors are raised because there are more than 1 element in `rankings` or in `brands` .. I can?t really figure out what wrong in my way to use `eachLike`and `like` .. Here is below an extract of the error raised in the verification: ```Description of differences -------------------------------------- * Actual array is too long and should not contain "pzc" at $.recommendations[0].rankings[0].brands[1] * Actual array is too long and should not contain a Hash at $.recommendations[0].rankings[1]```

matt.fellows
2021-07-28 01:15
that looks like the right setup to me, could you please share the resulting pact file?

matt.fellows
2021-07-28 02:03
It might be my eyes, but it looks like you are running the project in `d:` , but the import is trying to find a file in `c:`

consulting
2021-07-28 02:06
wow

consulting
2021-07-28 02:07
I wanted to clean that up... it bit me in the a$$ before I was able to find time to do it :slightly_smiling_face: Thanks Matt, it's a great lead!

consulting
2021-07-28 02:08
In the mean time, I got desperate with Mocha, so I tried to move on to Jest... It turns out that I found an example that works with Angular, Pact and Jest! Tomorrow (I'm in Montreal, Quebec :slightly_smiling_face: ), I'll try to start a new project from scratch with Jest and see if I understood everything that's at stake! Interesting fact: with Jest, none of the problems faced with Mocha seems to be present (no need to use a shim to fake a DOM and fix zone.js, no ESM to load modules, ...)

matt.fellows
2021-07-28 02:14
I think Jest uses Jasmine under the hood (I may be wrong about that) so could explain some of those compatibilities

consulting
2021-07-28 03:09
unfortunately, the `c:` reference was indeed wrong BUT also an old capture (sorry, my bad)... I use relative path since the beginning and that was an attempt to figure out why "./weather.service" could not be loaded... I also tried using required() instead of import... thinking Mocha is meant for a Node world and it could help... but it didn't change anything.

consulting
2021-07-28 03:10
I'll focus on Jest tomorrow to be able to tackle the provider side and Pact Broker and have something to show at work :slightly_smiling_face:

vbhardwaj.eminent
2021-07-28 05:15
has joined #pact-js

nathan.derave
2021-07-28 07:13
Hey @matt.fellows! Thanks for having a look (and thanks for Pact generally speaking, it?s huge man). Here is the resulting Pact file (there are a bit more stuffs in there as I defined other interactions and there are other fields as well): ```{ "consumer": { "name": "Recommendations Gateway" }, "interactions": [ { "description": "Fetch recommendations", "providerStates": [ { "name": "Has recommendations" } ], "request": { "headers": { "content-type": "application/json", "x-api-key": "asdf" }, "matchingRules": { "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "/api/recommendations/.+" } ] } }, "method": "GET", "path": "/api/recommendations/asdf" }, "response": { "body": { "context_id": "cc812d76-b5af-4a1b-a7be-e63115e19bbd", "recommendations": [ { "external_rankings": false, "followable": { "display_forms": [ { "language": "nl", "text": "Verinigd Koninkrijk" } ], "followed": true, "id": "article_location_verenigd-koninkrijk", "source": "article", "stats": { "df": 12636, "idf": 6.05343245, "n_recent_articles": 59 }, "type": "location", "value": "verenigd-koninkrijk" }, "list_position": 0, "rankings": [ { "brands": [ "pzc" ], "image_url": "https://cdn.businessinsider.nl/wp-content/uploads/2021/02/602f006e97cf0.png", "item_url": "https://cdn.businessinsider.nl/wp-content/uploads/2021/02/602f006e97cf0.png", "list_position": 2, "publication_date": "2021-05-27T06:50:54.835Z", "short_id": "edd20ce", "suggested_brand": "ad", "title": "Kijktips voor de donderdagavond", "type": "article" } ] } ] }, "headers": { "content-type": "application/json" }, "matchingRules": { "body": { "$": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*[*].followable.display_forms": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*[*].rankings": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*[*].rankings[*].brands": { "combine": "AND", "matchers": [ { "match": "type" } ] } } }, "status": 200 } }, { "description": "Fetch recommendations", "providerStates": [ { "name": "Something went horribly wrong" } ], "request": { "headers": { "content-type": "application/json", "x-api-key": "asdf" }, "matchingRules": { "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "/api/recommendations/.+" } ] } }, "method": "GET", "path": "/api/recommendations/asdf" }, "response": { "status": 503 } }, { "description": "Fetch recommendations", "providerStates": [ { "name": "recommendations not found" } ], "request": { "headers": { "content-type": "application/json", "x-api-key": "asdf" }, "matchingRules": { "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "/api/recommendations/.+" } ] } }, "method": "GET", "path": "/api/recommendations/asdf" }, "response": { "status": 404 } } ], "metadata": { "pactJs": { "opts:port": "6234", "version": "10.0.0-beta.44" }, "pactRust": { "version": "0.9.4" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "Guide Ranker" } }```

matt.fellows
2021-07-28 07:15
Thanks for the kind words :pray:

matt.fellows
2021-07-28 07:16
Is the consumer and provider both Pact JS?

matt.fellows
2021-07-28 07:16
It looks like the consumer is being produced by the new beta interface (produces a v3 pact file), but the provider is being verified by the old one, which only supports v2 pacts.

matt.fellows
2021-07-28 07:17
One option is to set the spec version to 2 (i don?t think that?s currently supported, but is easy to add and can do that for you quickly)

matt.fellows
2021-07-28 07:17
if the provider is also Pact JS, you just need to verify it with the v3 interface too

miguel.panelo
2021-07-28 07:29
has joined #pact-js

nathan.derave
2021-07-28 07:37
Aaah yes okay that?s true indeed. Consumer is JS and Provider is verified with Python. That definitely must be it. Now is see in the first lines of the https://github.com/pact-foundation/pact-python docs that it currently supports v2 specs only.

nathan.derave
2021-07-28 07:40
So I guess we can either tweak the consumer spec version generation (and that would require a PR for the ability to do it - thanks for proposing) OR I can switch my provider verification process to use the https://github.com/pact-foundation/pact-provider-verifier CLI. Is that correct ?

otaviio
2021-07-28 07:57
has joined #pact-js

matt.fellows
2021-07-28 09:21
Yep, I'd use the newer one which supports v3 though: https://docs.pact.io/implementation_guides/rust/pact_verifier_cli/

matt.fellows
2021-07-28 09:21
The other one is essentially what you're using now

matt.fellows
2021-07-28 09:21
Can you please raise a feature request on pact JS to be able to set the spec version?

matt.fellows
2021-07-28 09:22
I'll get to it this week

nathan.derave
2021-07-28 09:43
Cool I?ll make my verification to use the latest CLI Docker image ! Thanks for the support @matt.fellows. I?ll also open the feature request !


patrice.krakow
2021-07-28 10:00
has joined #pact-js

nathan.derave
2021-07-28 12:08
Running the verification with https://hub.docker.com/r/pactfoundation/pact-ref-verifier solved my issue !

david.simpson
2021-07-28 12:51
has joined #pact-js

e.alderson004
2021-07-28 17:17
has joined #pact-js

jdalessandro
2021-07-29 07:27
has joined #pact-js

eric.tang1
2021-07-29 16:22
has joined #pact-js

antklim
2021-07-29 22:25
has joined #pact-js

toffer.lim87
2021-07-30 03:51
has joined #pact-js

toffer.lim87
2021-07-30 03:59
Hello. I have a question regarding if Pactflow supports WebSocket APIs in API Gateway? The reason why I am asking is that, I been trying to Verify my Consumer contract and I am getting some error. I have a full AWS Credentials for our Service and have the correct config. I have tried using both localhost and a live api endpoint that my team is using. Also, we are using jest to run both Consumer and Provider pact test. If you can please point me to a documentation that would be awesome. Thank you! ```Error making request - SocketError getaddrinfo: nodename nor servname provided, or not know , attempt 1 of 3 ..... .....```

matt.fellows
2021-07-30 04:46
It doesn't support websockets

matt.fellows
2021-07-30 04:46
Is this a consumer or provider test?

matt.fellows
2021-07-30 04:47
I should say, it doesn't communicating over websockets, but you can test a websockets integration using message pact

tjones
2021-07-30 05:31
This looks like a configuration error that is unrelated to Pact. If you can share your code, we can check to see if it's a Pact problem.

aphronio
2021-07-30 13:42
has joined #pact-js

toffer.lim87
2021-07-30 18:13
Sorry. I cannot share any code because its the property of the company.

toffer.lim87
2021-07-30 18:34
And that is for the Provider Test. Thank you for the answers. =)

matt.fellows
2021-07-30 22:44
How about you make an example that shows the problem without showing your code?

matt.fellows
2021-07-30 22:44
It's hard to give advice without detail

matt.fellows
2021-07-30 23:10
The exception shows you haven't given a valid provider address to the verifier and/or it doesn't know how to communicate to the provider

fabio882
2021-08-01 19:31
has joined #pact-js

mike.key
2021-08-02 03:01
has joined #pact-js

eddie
2021-08-02 04:08
has joined #pact-js

michel.neufeglise
2021-08-02 12:57
Hi. Did anyone else also encounter a ruby binary error on windows, it is saying that GEM_HOME and GEM_PATH can not be found but there is a ruby 2.6.0 installation with those paths present on the windows machine

tjones
2021-08-02 22:11
Hmm. Can you post the exact error?

tjones
2021-08-02 22:12
It could be the long path issue - Ruby on windows isn't able to read paths longer than around 260 characters (even in windows 10 where long path support is native)

tjones
2021-08-02 22:13
You can test this by moving the project to a very short path

tjones
2021-08-02 22:14
Which version of pact-node do you have? (it will be in the logs, or you can get it with `npm ls @pact-foundation/pact-node`)

matt.fellows
2021-08-02 22:23
You don?t need Ruby on the machine for it to work Michel

matt.fellows
2021-08-02 22:26
Might be worth checknig if you have any other Ruby env vars about, and removing them

matt.fellows
2021-08-02 22:26
removing the bundler cache dir (`rm -rf ~.bundle` ) fixed it for another user

consulting
2021-08-03 15:16
Here's the tutorial on youtube that helped me figuring it out for the Angular side: https://www.youtube.com/watch?v=OZz7UyHnyKg

matt.fellows
2021-08-04 01:12
Thanks for sharing, just added to our docs site (will take 10 mins or so to update)

consulting
2021-08-04 03:57
I just started from scratch to have something as clean as possible. For the ui, I used Angular'S Tour of Heroes tutorial as a clean base. Comparing with that tutorial, other than using Jest, the notable change that needs to be made to a vanilla Angular project is setting these properties to *true* in *tsconfig.spec.json* *"emitDecoratorMetadata": true,* *"experimentalDecorators": true*

consulting
2021-08-04 03:57
Also, changing these didn't apply until a restart of the server... which made it harder for me to pin point :slightly_smiling_face:

matt.fellows
2021-08-04 04:00
The more angular examples/resources the better. Perhaps we should add a basic one on the JS repo or elsewhere once we have a working one

consulting
2021-08-04 04:02
I'm almost done with mine... I can share it to you in Github once it's "decent". Could serve as is or as a base to some other examples you guys would want to create

consulting
2021-08-04 04:03
Thanks again for your support Matt! It felt great knowing I could bounce ideas with you when things got a bit rough :smile:

matt.fellows
2021-08-04 04:09
you?re welcome!

tylerkron
2021-08-04 14:02
has joined #pact-js

thanuxxxx
2021-08-04 17:41
Question about `Matchers` I have a response like this ```"categories": { "additionalProp1": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp2": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp3": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 } }``` so `additionalPropX` is repeating (at least one or more). Do we have any method like `eachLike`


thanuxxxx
2021-08-05 01:17
Do pact V3 support with PactWithJest?


thanuxxxx
2021-08-05 01:23
Cool thank you!!

marvin.kienitz
2021-08-05 07:20
has joined #pact-js

danieljak
2021-08-05 10:09
has joined #pact-js

consulting
2021-08-05 12:59
Hi Matt, Now that I'm testing the provider, I see some differences on the body structure pertaining to matchers. Here's my response: ```"response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::SomethingLike", "contents": [ { "id": 1, "name": "Superman" }, { "id": 2, "name": "Batman" }, { "id": 3, "name": "Ironman" } ] } }``` As you can see, in my case, the matcher information it stuffed inside the body of the response. When I compare my contract with the one generated by the tutorial I shared with you earlier in this conversation, it's looking much closer to what is shown during your part 3 video (pactflow youtube channel): ```"response": { "status": 200, "headers": { }, "body": [ { "id": "1", "make": "Tesla", "model": "S" }, { "id": "2", "make": "BMW", "model": "3Series" } ], "matchingRules": { "$.body": { "match": "type" } } }``` Having this information in the body is messing up with my provider contract test (I feel that attribute "json_class" and "content" should be outside of "body"). Any idea why I get this structure in my contract? (version maybe?) Interesting fact: even though I copied the package.json file from the tutorial, I get slightly different versions in package.lock.json for pact (me:9.16.0, tutorial:9.14.0) and pact-node (me:10.13.1, tutorial: 10.11.1)

matt.fellows
2021-08-05 13:02
I?ve seen that problem before, one moment


matt.fellows
2021-08-05 13:03
It?s one of those ?intermittent? problems, but should be solved in the latest version

univ.anirudh
2021-08-05 13:22
has joined #pact-js

univ.anirudh
2021-08-05 13:28
Hi, I've been trying to understand the scope of the provider implementation of a pact test. https://docs.pact.io/consumer/contract_tests_not_functional_tests according to the last point in this, whether the provider does the "right" thing with the request should be left to the provider's functional tests. What I understand from this is, we would ignore (or mock) out the layer beyond the handler/validator function for a pact. So no db/networking interaction. Is that the correct way to think about it?

thanuxxxx
2021-08-05 15:51
I am getting *Error* `No value provided for required options '--pact-helper'` after switching to `jest-pact/v3` any idea?

thanuxxxx
2021-08-05 15:54
Even just copied/pasted this example code .. ```import { pactWith } from 'jest-pact/v3'; import { MatchersV3 } from '@pact-foundation/pact/v3'; import api from 'yourCode'; pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, (interaction) => { interaction('A request for API health', ({ provider, execute }) => { beforeEach(() => provider .given('Server is healthy') .uponReceiving('A request for API health') .withRequest({ method: 'GET', path: '/health', }) .willRespondWith({ status: 200, body: { status: MatchersV3.like('up'), }, }), ); execute('some api call', (mockserver) => api(mockserver.url) .health() .then((health) => { expect(health).toEqual('up'); }), ); }); });```

james.perepiczka
2021-08-05 16:29
has joined #pact-js

j3rry.wan9
2021-08-05 21:44
has joined #pact-js

tjones
2021-08-05 23:05
Which versions are you uising?

thanuxxxx
2021-08-05 23:40
npm i -D @pact-foundation/pact@10.0.0-beta.16 jest-pact@0.9.0-beta.v3

thanuxxxx
2021-08-06 01:19
I copied from pact docs


sadikshahidain
2021-08-06 02:14
has joined #pact-js

consulting
2021-08-06 12:49
I tried with the latest version and I still have the same problem. I also tried to use 99% of the package.json file from the tutorial, expecting to get the same result as them, but didn't work either.

consulting
2021-08-06 12:49
I cleared npm cache just in case before doing any of those attempts

consulting
2021-08-06 12:57
did the same process of cleaning cache and re-installing everything with the tutorial and it still works

consulting
2021-08-06 12:57
both end up using "_id": "@pact_foundation_greet/pact@9.16.0",

matt.fellows
2021-08-06 12:58
That?s just Bizarre.

consulting
2021-08-06 12:58
yup

matt.fellows
2021-08-06 12:58
have you cleared the previous pact file out beforehand? (just thinking of things we can do here()

matt.fellows
2021-08-06 12:58
also, Windows/OSX/Linux?

consulting
2021-08-06 12:58
I'll try to compare everything in their config files (again) maybe I missed something

consulting
2021-08-06 12:59
windows 10

consulting
2021-08-06 12:59
by clearing the pact file, you mean deleting the contract generated? yes

consulting
2021-08-06 13:00
and I notice that this problem is also visible in the logs: ```I, [2021-08-06T08:47:30.499567 #25560] INFO -- : Registered expected interaction GET /heroes D, [2021-08-06T08:47:30.500567 #25560] DEBUG -- : { "description": "a request to get all the heroes", "providerState": "heroes exist", "request": { "method": "GET", "path": "/heroes" }, "response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::SomethingLike", "contents": [ { "id": 1, "name": "Superman" }, { "id": 2, "name": "Batman" }, { "id": 3, "name": "Ironman" } ] } }, "metadata": null } I, [2021-08-06T08:47:30.546849 #25560] INFO -- : Received request GET /heroes```

matt.fellows
2021-08-06 13:01
hmm thanks. The log I think always shows it that way (I maybe wrong abotu that though)

matt.fellows
2021-08-06 13:07
If you could possibly create a repo that we can use to reproduce the problem, we can definitely look into it

consulting
2021-08-06 13:12
I'll give it one more try... if I'm not successful, I'll take your invitation :slightly_smiling_face:

matt.fellows
2021-08-06 13:13
Thanks. I feel your frustration!

consulting
2021-08-06 13:16
I'm alright :slightly_smiling_face: no worries! I just can't wait to be able to make it work from both consumer and provider side AND have the broker working as well. The sad thing is that I have to do this on my spare time, which is pretty thin lately :disappointed:

consulting
2021-08-06 13:59
(just keeoing notes here so you know what I did so far in case yuou finally end up looking at it :slightly_smiling_face: )

consulting
2021-08-06 14:00
I deleted all the files from the tutorial folder except the node_moduels folder. Copied my files in that tutorial folder. Ran ng Serve to compile things and then ng test to generate a new contract. Result: same.

consulting
2021-08-06 14:00
Last thing I want to compare is how I build my interactions...

consulting
2021-08-06 14:19
Interactions are exactly the same. Ok, I'll take your proposal :slightly_smiling_face:

consulting
2021-08-06 14:19
I officially need help :relaxed:


univ.anirudh
2021-08-06 15:00
Bump on this, any help would be highly appreciated

thanuxxxx
2021-08-06 15:39
It works with `"@pact-foundation/pact": "10.0.0-beta.17"`

consulting
2021-08-06 16:44
I FOUND IT!!!!!!!!!!!!!!!!!!

consulting
2021-08-06 16:46
I was trying to produce different versions of the contract... so when I changed from spec:1 to spec:2, the structure of the contract was as expected (without the "json_class" and "content" extra key and WITH the matchingRules key!)

consulting
2021-08-06 16:49
looking back at the tutorial, they are using spec:3, which explains why it was working for them.

consulting
2021-08-06 16:50
here's the conclusion. When instantiating a new Pact : ? Without "spec" option, generated contract will be ok ? With "spec" option greater than 1 and smaller than 10, generated contract will be ok ? With "spec" *starting* with 1 (1, 10-19, 100-199, etc), generated contract will be malformed

consulting
2021-08-06 17:05
Note also that in the generated contract, the version number doesn`t reflect the value passed when instantiating the new Pact, having the spec starting with 1. In other words, for 1, 11, 14, 129, etc... you will have this version number appearing: ```, "metadata": { "pactSpecification": { "version": "1.0.0" } }```

consulting
2021-08-06 17:05
and it's defaulted to "2" when no spec is provided.

consulting
2021-08-06 17:06
that's it men! hope this helps! I'll just use spec:2 to be able to move forward!

ganginenik
2021-08-06 18:14
has joined #pact-js

matt.fellows
2021-08-06 22:08
We did an AMA on this that might be helpful https://docs.pact.io/help/amas/#north-america-2

matt.fellows
2021-08-06 22:09
I usually mock out 3rd party systems, but not code within the provider unless it's more convenient

matt.fellows
2021-08-06 22:09
Its not that you can't do functional testing as a side effect, it's just not Pact's primary goal

matt.fellows
2021-08-06 22:21
oh my goodness!

matt.fellows
2021-08-06 22:21
We should just prevent other versions from being specified there

matt.fellows
2021-08-06 22:22
`spec: 1` is old now, and pretty much noone would be using that

matt.fellows
2021-08-06 22:23
`spec: 3` using the current version of JS would also have no effect

matt.fellows
2021-08-06 22:23
so you?re right, `2` is where it?s at (you?re not using the new beta)

consulting
2021-08-07 00:50
I thought it was meant for the users to specify their version of the contract

consulting
2021-08-07 00:50
now I get it, thanks!

consulting
2021-08-07 00:56
lol "spec" would have been a bad name for what I thought it was meant... I should have understood earlier :relaxed: I notice that the effect of that value is undeniable at the end of the generated contract ```"metadata": { "pactSpecification": { "version": "2.0.0" } }```

consulting
2021-08-07 01:16
I'm all good now! I created an account of Pactflow, published consumer and provider, everything works! I just need to add another consumer for the same provider to make things a bit more interesting, clean everything up and I'll be good for my demo :)

matt.fellows
2021-08-07 01:48
Awesome to hear Pascal, thanks for that persistance

matt.fellows
2021-08-07 01:49
FYI I also updated https://github.com/pact-foundation/pact-js/issues/719 as a result of this thread

univ.anirudh
2021-08-07 06:33
So, for example, if I was testing a contract that required pre-existing data, the correct way to do it would be to set up the state required (insert records in db etc), run the contract test (which would trigger validations etc throughout the flow) but not verify whether the correct side effects occurred?

tjones
2021-08-07 11:39
There's no one correct way to do this, as such

tjones
2021-08-07 11:39
A lot depends on how your architecture is

tjones
2021-08-07 11:40
For example, I prefer to mock the repository layer in your service, since that's typically expressed in business language

tjones
2021-08-07 11:40
So, you can say `"when user with Id 1 exists -> getUser(1) will return (<some specific business object>)"`

tjones
2021-08-07 11:41
I find that more convenient than describing it in terms of insert statements etc

tjones
2021-08-07 11:42
Can you try with a more recent version?

thanuxxxx
2021-08-07 16:42
works with this version "@pact_foundation_greet/pact": "10.0.0-beta.44", I think I also had to clean node_module.

tjones
2021-08-08 13:08
Possibly a broken version. I'll update the documentation.

tjones
2021-08-08 13:12
Thanks for letting us know!

tjones
2021-08-08 13:13
There's nothing in the specific version from the documentation. jest-pact will work with any version of the beta pact-js branch.

tjones
2021-08-08 13:13
(I suspect the problem in this case was to do with that version of the beta branch, not jest-pact)

brentbarker9
2021-08-09 19:01
Hi, question: I'm having this issue: https://github.com/pact-foundation/karma-pact/pull/21/commits/f7a565dbe5789da7618ad80450fff213d8066ccd but the last karma-pact version was published in 2019. (https://www.npmjs.com/package/@pact-foundation/karma-pact) how can I get the latest version with that fix?

brentbarker9
2021-08-09 19:02
Of course after I ask the question I see that it is tagged with v2.3.1

brentbarker9
2021-08-09 19:02
hmm

brentbarker9
2021-08-09 19:09
```[2021-08-09 19:06:54.195 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Starting pact binary 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service', with arguments [service --port 3160 --consumer angular-project --provider edie --log-level DEBUG --log /home/dev/ui/angular-project/pacts/stubserver-integration.log --pact_dir /home/dev/ui/angular-project/pacts --host localhost --pact-file-write-mode overwrite] [2021-08-09 19:06:54.208 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Created 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service' process with PID: 1933 09 08 2021 13:06:54.220:ERROR [karma-server]: Server start failed on port 9876: Error: connect ECONNREFUSED 127.0.0.1:3160 [2021-08-09 19:06:58.933 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] INFO WEBrick::HTTPServer#start: pid=1933 port=3160 [2021-08-09 19:06:54.195 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Starting pact binary 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service', with arguments [service --port 3160 --consumer angular-project --provider edie --log-level DEBUG --log /home/dev/ui/angular-project/pacts/stubserver-integration.log --pact_dir /home/dev/ui/angular-project/pacts --host localhost --pact-file-write-mode overwrite] [2021-08-09 19:06:54.208 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Created 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service' process with PID: 1933 09 08 2021 13:06:54.220:ERROR [karma-server]: Server start failed on port 9876: Error: connect ECONNREFUSED 127.0.0.1:3160 [2021-08-09 19:06:58.933 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] INFO WEBrick::HTTPServer#start: pid=1933 port=3160``` this is the error I get with node 12.11, it works with node 12.10

leonardo.viana
2021-08-09 20:02
Hi all. I?m using the latest version of pact-js v3 beta (10.0.0-beta.44) to write our provider tests and I?m having a little issue. All the tests run and pass, and the results are even successfully published to the broker, but at the very end we get the crash below, which has pact-foundation/pact/native/index.node in one of the paths (we are running tests with jasmine on nodejs 10): ```FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope 1: 0x8dbaa0 node::Abort() [node] 2: 0x8dbaec [node] 3: 0xad81ba v8::Utils::ReportApiFailure(char const*, char const*) [node] 4: 0xe95d67 v8::internal::HandleScope::Extend(v8::internal::Isolate*) [node] 5: 0xaecbfc v8::Isolate::GetCurrentContext() [node] 6: 0x8a8665 node::EmitAsyncDestroy(v8::Isolate*, node::async_context) [node] 7: 0x7f91b2d826e2 [/git/pnr-policy/node_modules/@pact-foundation/pact/native/index.node] 8: 0xa43fc5 [node] 9: 0xa4833f [node] 10: 0xa59028 [node] 11: 0xa48c7b uv_run [node] 12: 0x8e6255 node::Start(v8::Isolate*, node::IsolateData*, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&) [node] 13: 0x8e44a2 node::Start(int, char**) [node] 14: 0x7f91ba3a9f45 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6] 15: 0x89ed45 [node] Aborted (core dumped) ``` Could this be a bug in the pact native library?

george.south
2021-08-09 21:51
@george.south has left the channel

uglyog
2021-08-09 23:00
No, that looks like a V8 issue when shutting down

brentbarker9
2021-08-09 23:51
`@pact-foundation/pact-node@10.12.2` works just fine

brentbarker9
2021-08-09 23:51
All other js libs are latest for me

brentbarker9
2021-08-09 23:51
```npm install --save-dev @pact-foundation/pact-web@latest @pact-foundation/pact-node@10.12.2 @pact-foundation/karma-pact@latest @pact-foundation/pact@latest```

xiaoyewang
2021-08-10 01:13
has joined #pact-js

tjones
2021-08-10 01:16
V8 doesn't normally have issues, though. Are we (or neon) maybe not cleaning up something?

uglyog
2021-08-10 01:19
Possibly. It looks like an async destroy is not running correctly

mfellows_admin
2021-08-10 02:52
has joined #pact-js

tjones
2021-08-10 05:37
@leonardo.viana: Nodejs 10 has passed EOL - do you still get this error with a Maintenance (12) or Active LTS (14) version?

tjones
2021-08-10 05:38
Also, if you're able to reproduce this in a repo we can take a look and make sure it's not us.

tjones
2021-08-10 05:42
Ah, are you asking for a release of karma-pact? We can certainly do this. The reason it wasn't released before is that package hasn't been migrated to github actions, and travis no longer runs our build pipelines.

tjones
2021-08-10 05:43
However, we're considering dropping support for pact-web and karma-pact - if this is something you need, I'd love your thoughts here: https://github.com/pact-foundation/pact-js/issues/626

tjones
2021-08-10 05:44
I will try to manually release karma-pact tonight

vbhardwaj.eminent
2021-08-10 06:56
Hi, Reaching out to know your thoughts on the approach which I am planning to follow on consumer side:   1. Test and publish pact using MSW mock 2. Use swagger mock validator to validate the mocks 3. Deploy to test/prod   My thinking behind this is that it will give faster feedback and release to test/prod. Whereas, the other approach where I am suppose to call the provider to validate the contract will be slower.


matt.fellows
2021-08-10 06:59
also, how are you goinng to validate your swagger is compatible with your API?

matt.fellows
2021-08-10 06:59
but yes, that?s doable

vbhardwaj.eminent
2021-08-10 07:05
thanks for suggesting msw-pact, I will have a look

tjones
2021-08-10 07:06
This looks awesome, @yousafn!!

matt.fellows
2021-08-10 07:13
How are you planning on managing the contracts?

vbhardwaj.eminent
2021-08-10 07:19
through versions

vbhardwaj.eminent
2021-08-10 07:19
I have done the implementation of swagger on service which automatically generates the `swagger-ui/index.html#`, which I assume will be correct.

vbhardwaj.eminent
2021-08-10 07:21
i can get the json from swagger

tjones
2021-08-10 07:43
Just be careful with swagger-mock-validator as at best it can give you a "maybe" rather than a "yes" for compatibility


qingyuliu
2021-08-10 09:27
has joined #pact-js

leonardo.viana
2021-08-10 15:14
I forgot to mention yesterday, but the issue disappeared after I upgraded nodejs from 10.14.0 to 10.24.1.

brentbarker9
2021-08-10 16:49
Sorry I believe the problem is in pact-node, not karma-pact after investigating the problem further. We are actively using karma-pact though

dhairyapatel071996
2021-08-10 20:06
has joined #pact-js

beem132
2021-08-10 21:21
has joined #pact-js

rfang
2021-08-11 00:49
has joined #pact-js

tjones
2021-08-11 01:26
Ok. Can you try an earlier version of pact-node?

tjones
2021-08-11 04:49
:man-shrugging: Maybe it was a V8 issue after all

tjones
2021-08-11 04:51
It might also be an issue with neon (which we use for the bindings where the issue was), because you're using an outdated version of node. Neon supports "the latest Node version and all LTS releases"

vbhardwaj.eminent
2021-08-11 07:09
very interesting conversation @tjones, I read it once, very deep and technical. I will have to go through it few more times to understand it completely. But according to me the jest of it is that one should understand clearly the trade offs with swagger mock validator. Thanks for sharing!

subhashnarla
2021-08-11 07:29
has joined #pact-js

tjones
2021-08-11 09:40
That's exactly right.

jkdihenkar
2021-08-11 10:43
has joined #pact-js

christian.kampka
2021-08-11 10:51
has joined #pact-js

ashwinparthasarathy30
2021-08-11 11:23
has joined #pact-js

andrew.jensen
2021-08-11 16:18
has joined #pact-js

pedroefajardo_pactio
2021-08-11 16:49
@andrew.jensen

tjones
2021-08-11 22:51
Thinking about this some more, I?m curious to know where the two endpoints understanding came from- I believe we only have one state handler endpoint, so perhaps we need to update some of the documentation

vivekkurhe1993
2021-08-12 03:44
has joined #pact-js

vbhardwaj.eminent
2021-08-12 05:00
Hi, How can I send the path variable while writing the Pact interactions so that I can read them on the provider side? My consumer is in React-JS-Jest and provider in springboot and java. I know in java I will receive the params in `(Map<String, Object> params)` but as of now it is coming as empty. My consumer side pact interaction looks like this

matt.fellows
2021-08-12 05:10
Normally you would just setup a provider state so that you can deal with (what I assume is the ID): `18297`

matt.fellows
2021-08-12 05:11
The current main version of PactJS doesn?t have that capability though, you need to use the beta (see this example: https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/provider-state-injected)

matt.fellows
2021-08-12 05:11
IMO it?s a bit of a code-smell, so you should question if you really need to use it before you do

vbhardwaj.eminent
2021-08-12 05:19
my provider is consumed by both web and mob, if I can get the path variables from pact broker and in provider I can use `(Map<String, Object> params)`, then I would not need to hard code on provider side. As of now I am hard coding on provider side - `this.xxxxxx.xxxxxxxxComponentByCategoryId("WEB", 18297L);` My intention is to achieve this on provider side `@State(value = "ccccccccc", action = StateChangeAction.SETUP)` `public void retrieveDSL(Map<String, Object> params) {` `this.xxxxxx.xxxxxxxxComponentByCategoryId((String)params.get("client"), ((Number)params.get("categoryId")).longValue());` `}`

matt.fellows
2021-08-12 05:20
the example I shared above answers this

matt.fellows
2021-08-12 05:20
it?s only available in the new beta package though

vbhardwaj.eminent
2021-08-12 05:22
I am bit reluctant to go for beta

matt.fellows
2021-08-12 05:27
:man-shrugging:

matt.fellows
2021-08-12 05:27
We?re working to get it out of beta, but that will take some time

vbhardwaj.eminent
2021-08-12 05:27
that means provider has to hard code the arguments until we get v3 for consumer (in case I am not ready for beta)

matt.fellows
2021-08-12 05:27
that?s what provider states are for anyway

vbhardwaj.eminent
2021-08-12 05:29
are you suggesting that one should not use (Map<String, Object> params), instead hard code it so that the test data is loosely coupled

matt.fellows
2021-08-12 05:30
I?m just saying that?s how you do it without injecting provider state values (which is what you?re asking about)

matt.fellows
2021-08-12 05:30
we just call them provider states ?given that resource with ID 12345 exists? is the state, your state handler makes sure that resource exists or the stub is setup etc.

vbhardwaj.eminent
2021-08-12 05:38
I think I got your point, with Pact we are not targeting to assert exact values. The moment we start focusing on exact match of values the test will become brittle and will not be manageable. As long as data type and field name are matched, consumer and provider should be happy, pact will be successful.

matt.fellows
2021-08-12 05:38
that general point is indeed correct

matt.fellows
2021-08-12 05:39
but you have identified one of the scenarios where exact values matter - in this case, on the provider side the test _will_ need to send a request to path `/xxxxxx/18297` so the state handler must know how to prep that

vbhardwaj.eminent
2021-08-12 05:41
I have learnt this after today's discussion, now I will use matcher to be flexible on the path variables

matt.fellows
2021-08-12 05:42
The matcher only works on the consumer side though, not the provider side

matt.fellows
2021-08-12 05:42
(matchers on the request only apply to the consumer, matchers on the response only apply to the provider)

vbhardwaj.eminent
2021-08-12 05:43
thankfully I got that point after playing alot with your pact Js workshop

matt.fellows
2021-08-12 05:43
great!

vbhardwaj.eminent
2021-08-12 05:43
ahh, finally I have started speaking your Pact language:grinning:

vbhardwaj.eminent
2021-08-12 05:43
I am feeling happy

matt.fellows
2021-08-12 05:43
:rolling_on_the_floor_laughing:

aakbar
2021-08-12 06:05
has joined #pact-js

tm.buga
2021-08-12 08:55
has joined #pact-js

yanivhad
2021-08-12 08:58
has joined #pact-js

francois.fernandes
2021-08-12 11:55
has joined #pact-js

christian.kampka
2021-08-12 13:04
I have a question about how to construct the path attribute of the provider interaction. The api sais it can be either a string or a MatcherResult, but it is obviously not as simple as `/product/${Matchers.like(5)}` Can anyone offer some guidance on this?

matt.fellows
2021-08-12 13:06
It?s rare you need a matcher on the request path, can you not control which path your unit test is sending the request to?

christian.kampka
2021-08-12 13:08
No, I can control it well. Maybe I missunderstood the purpose of the matchers. My understanding is that a matcher is used so that consumer and producer do not need to "match" on the excat value that is matched but only the "type"

christian.kampka
2021-08-12 13:09
but now that I think about it, I see how that is useful for the response but using it for paths is actually hard to fathm

matt.fellows
2021-08-12 13:11
Yeah, as soon as you stop to think about it you realise it only helps the consumer unit test, so most times not needed

matt.fellows
2021-08-12 13:12
the request to the provider can?t have a matcher, it needs to be a real one (there is a feature to inject a provider state value there, but that?s a separate thing altogether)

christian.kampka
2021-08-12 13:17
So if I understand it correctly, if I use `body: Matchers.like({foo: 1, bar: 2})` the producer has to fulfull the structure of the object, eg. `{foo: 2, bar: 3}` would match while `{foo: 2, bar: "adsf"}` would not, correct?

christian.kampka
2021-08-12 13:18
if so, is that check "deep", eg. does it match nested objects ?

christian.kampka
2021-08-12 13:24
OR - would I actually have to specify every very concretely, eh: `{foo: http://Matchers.int(1), bar: http://Matchers.int(2)}` ?

matt.fellows
2021-08-12 13:25
no, the matcher cascades

matt.fellows
2021-08-12 13:25
it will cascade until you stop it, by using a different matcher

matt.fellows
2021-08-12 13:26
even if the property value is an array, it now expects an array of objects that have the same structure

christian.kampka
2021-08-12 13:27
maybe I am missing something, but it sounds like `body: Matchers.like(expectedObject)` is what I want in the majority of all cases

tjones
2021-08-12 13:39
Yes, this is correct

tjones
2021-08-12 13:39
(but not always)

christian.kampka
2021-08-12 13:40
As always :smile:

tjones
2021-08-12 13:40
examples include where you need specific strings, like: ```{ type: "some_string_you_switch_on" otherProperty: Matchers.like(...) }```

christian.kampka
2021-08-12 13:40
thanks, guys, much apprechiated

tjones
2021-08-12 13:42
or where you want to have eg dates

tjones
2021-08-12 13:43
while we're on the topic, I don't think this is well documented, but we also have `Matchers.extractPayload()`, in case you want to strip the matchers off an example

tjones
2021-08-12 13:45
this is handy for the case where the object you get out of the client is the same as the json payload. ```const body = Matchers.like(/*whatever */); .... setup interaction using body it("returns the expected payload", () = { expect(yourApi.someCall()).toEqual(Matchers.extractPayload(body)); })```

christian.kampka
2021-08-12 13:45
that one I already found :slightly_smiling_face:

tjones
2021-08-12 13:46
awesome. I want to tidy up the docs so people don't have to use the source

christian.kampka
2021-08-12 13:47
something like this probably won't work, right? ```{ ...Matchers.like(fullObject), type: "some_string_you_switch_on" }```

christian.kampka
2021-08-12 13:49
I mean it works on the unit test level, but the pact matching rules don't seem to grasp it


tjones
2021-08-12 13:49
I think that won't work

tjones
2021-08-12 13:49
but that's a really nice example.

tjones
2021-08-12 13:49
I wonder if we can make a DSL to improve that case

tjones
2021-08-12 13:50
sorry, let me be more specific - that won't work.

tjones
2021-08-12 13:52
You can do this though: ```Matchers.like({ ...fullObject, type: Matchers.term({ generate: "some_string_you_switch_on", matcher: "some_string_you_switch_on"}) })```

tjones
2021-08-12 13:52
with the caveat that `matcher` is a regex, so you might have to escape some things in the string, depending.

tjones
2021-08-12 13:54
Maybe we could make that nicer with the following (unimplemented) examples: ```{ ...Matchers.likeEachProperty(fullObject), type: "some_string_you_switch_on" }``` and ```Matchers.like({ ...fullObject, type: Matchers.exactString("some_string_you_switch_on") })```

tjones
2021-08-12 13:54
Maybe `eachPropertyLike`

christian.kampka
2021-08-12 13:56
That would be really cool :slightly_smiling_face:


brentbarker9
2021-08-12 16:39
yep, the earlier versions of pact node work (`10.12.2` and lower). The breaking change was introduced in `10.13.0`

thanuxxxx
2021-08-12 19:40
@matt.fellows for this response ```"categories": { "additionalProp1": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp2": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp3": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 } }``` I have something like this ``` categories: eachKeyLike('XXXXXXXXXXXXX', { id: string('XXXXXXXXXXXXX'), items: atLeastOneLike('FFFFFFF'), }),``` That will address one nested object but what about all of others? What about min, and max repeats

matt.fellows
2021-08-12 22:29
That function doesn?t have min/max like the others, but is ?at least one?

thanuxxxx
2021-08-12 22:40
Excellent!! Thank you :relaxed:

tjones
2021-08-13 00:33
Can you try `karma-pact@3.0.0` ?

tjones
2021-08-13 00:35
and `pact-node@10.13.3`

johnathan.gilday
2021-08-13 16:40
has joined #pact-js

leonardo.viana
2021-08-13 17:44
Hi all. Very quick question? One can specify which pacts the provider verifies via `consumerVersionSelectors`. However, if `consumerVersionSelectors` is *not* provided, which pact(s) are verified by default?

ben.kaiser
2021-08-13 17:47
has joined #pact-js

johnathan.gilday
2021-08-13 20:03
@johnathan.gilday has left the channel

dbekman
2021-08-13 20:51
has joined #pact-js

matt.fellows
2021-08-14 00:11
Depends on what other options are sent

matt.fellows
2021-08-14 00:12
It may just grab the latest pacts

matt.fellows
2021-08-14 00:12
The output in the verifier will tell you what it selected and why

leonardo.viana
2021-08-14 00:16
Latest pact for same branch as the provider branch?

matt.fellows
2021-08-14 00:18
No, latest pact for that consumer

matt.fellows
2021-08-14 00:18
What config are you sending? Is this a hypothetical question?

matt.fellows
2021-08-14 00:19
You almost certainly don't want to verify only latest

matt.fellows
2021-08-14 00:28
Check the test output tho, it will explain what pacts have been selected and why

chen
2021-08-15 09:34
has joined #pact-js

tom.willmott
2021-08-16 13:47
has joined #pact-js

franklin.lucena89
2021-08-16 16:52
has joined #pact-js

leonardo.viana
2021-08-16 19:55
Hi all. I?m seeing some interesting things regarding pact file creation in pact-js v3 beta and I?m wondering if it?s expected. I?ll describe the 2 cases I?m seeing: 1. Let?s say I have 2 consumer tests, and I?ve run them such that the pact file has already been generated locally with both interactions. Now, let?s say that I edit the `uponReceiving` string slightly in one of those tests and re-run them. It turns out that pact will actually add a *third* interaction with the updated `uponReceiving` string to the existing pact file. I was expecting pact to simply regenerate the pact (e.g. overwrite the existing file) with the `uponReceiving` string updated in the appropriate interaction (meaning, the pact file would still have 2 interactions, rather than 3). 2. Again, let?s say I have 2 consumer tests, and I?ve run them such that the pact file has already been generated locally with both interactions. Now, let?s say I change a boolean value in the request body of one of them from true to false, and re-run them. It turns out that pact will *not* regenerate the pact file, which will still have the old true value for the boolean. The common thread here seems to be that pact files may not be re-generated properly if they already exist. Should I file an issue for this?

matt.fellows
2021-08-16 22:42
you need to remove any pact files before running the pact tests

matt.fellows
2021-08-16 22:43
It?s not clear though, so an issue being raised would be great thanks

matt.fellows
2021-08-16 22:43
We may be able to address it, but at least, making it clearer for now would be ideal

uglyog
2021-08-16 22:52
Changing the `uponReceiving` changes the key of the interaction, so Pact will think it is a different interaction. A clean before the tests are run will fix this issue.

leonardo.viana
2021-08-16 23:14
I get it that removing pact files before running tests avoid these issues. Is there any value, though, in doing for example, what?s described in issue 2 above (namely *not* updating the existing pact file with the new body values)? I was just wondering why doesn?t Pact overwrite existing pact files automatically, or at least provide an option to do so. For example, in `PactV3Options` there could be a boolean field, called something like `overwrite` , which when set to `true` would automatically overwrite any existing pact file with the one generated by the current run.

matt.fellows
2021-08-16 23:15
yep, that?s an option. Can you please raise a request as per above? I think there are a few things we can do

uglyog
2021-08-16 23:20
The second one must be a defect.

uglyog
2021-08-16 23:22
By default, the option is to merge the test interaction into the pact file. The reason for this is some people like to split the the tests up into multiple separate tests. In this case, if overwrite was the default then the second interaction will always replace the first one.

abatan.k
2021-08-16 23:31
Hello all :slightly_smiling_face: When im testing my provider, Pact complain about a JSON string, Pact doesn't parse JSON before checking against my consumer contract ??

uglyog
2021-08-16 23:33
It uses the content type to determine how to parse the body


matt.fellows
2021-08-17 00:40
can you please elaborate more on the error you?re getting @abatan.k?

leonardo.viana
2021-08-17 01:30
@tjones, I saw your comment about `pactfileWriteMode` and it?s good to see that something like that exists. I do see it defined as part of the `PactOptions` interface: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/dsl/options.ts#L50 However, I do not see a similar option for the equivalent `PactV3Options` interface: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/v3/pact.ts#L11 Is this something that will be added later?

matt.fellows
2021-08-17 01:56
That?s why we asked you to create the issue :slightly_smiling_face:

abatan.k
2021-08-17 02:25
@matt.fellows I got this error: ``` + "name": "Tether", + "symbol": "USDT" + } + }, + { + "id": "bcf198d0-7342-46d7-995f-e7886097fb9d", + "base": { + "id": "f33e7a5c-b38b-46de-b047-e4bc47366a8a", + "name": "0x", + "symbol": "ZRX" + }, + "quote": { + "id": "9a3a2bfb-522f-4d1c-a766-7eb62147fe80", + "name": "Tether", + "symbol": "USDT" + } + } + ] + } +] Description of differences -------------------------------------- * Expected a Hash but got a String ("[\n {\n \"id\": \"9b685255-2cb8-4f4a-8b41-4f231f78aabc\",\n \"name\": \"Binance\",\n \"pairs\": [\n {\n \"id\": \"42fd3c6e-bfce-429a-b76e-c2d00de68e5b\",\n \"base\": {\n \"id\": \"fe84d516-9336-46a4-a35f-b3e0e7f9140b\",\n \"name\": \"Bitcoin\",\n \"symbol\": \"BTC\"\n },\n \"quote\": {\n \"id\": \"9a3a2bfb-522f-4d1c-a766-7eb62147fe80\",\n \"name\": \"Tether\",\n \"symbol\": \"USDT\"\n }\n },\n {\n \"id\": \"2d50f549-07cb-4ca5-8f08-bf3b354c501a\",\n \"base\": {\n \"id\": \"4c49c19a-19b3-42b3-a031-cee8f07e84fa\",\n \"name\": \"Ethereum\",\n \"symbol\": \"ETH\"\n },\n \"quote\": {\n \"id\": \"9a3a2bfb-522f-4d1c-a766-7eb62147fe80\",\n \"name\": \"Tether\",\n \"symbol\": \"USDT\"\n }\n },\n {\n \"id\": \"2ebc0d2f-f647-4f13-a983-052aa81eea62\",\n \"base\": {\n \"id\": \"818185aa-d255-40f4-b41d-6291cdda0570\",\n \"name\": \"Bitcoin Cash\",\n \"symbol\": \"BCH\"\n },\n \"quote\": {\n \"id\": \"9a3a2bfb-522f-4d1c-a766-7eb62147fe8```

abatan.k
2021-08-17 02:25
I put juste a portion of it, but you can imagine the rest :slightly_smiling_face:

abatan.k
2021-08-17 02:30
I use Azure function, and in the docs, azure says that what im return from my azure function, is passed to `JSON.stringify` so i added the proper Headers to the response, bu i still get this error

abatan.k
2021-08-17 02:30
How can i make PACT use `JSON.parse` to do the comparison with my consumer contract ??

matt.fellows
2021-08-17 02:32
what does your pact file look like, can you pleaes share?

matt.fellows
2021-08-17 02:32
You probably need to add an expected `content-type` of `application/json` in the conumer test

abatan.k
2021-08-17 02:37
ok i didn't rebuild my typescript codebase sorry :sweat_smile:

abatan.k
2021-08-17 02:37
but now, i got this error `Expected a Hash but got a Array`

abatan.k
2021-08-17 02:37
Here is the body of my consumer test

abatan.k
2021-08-17 02:38
```body: Matchers.eachLike({ id: Matchers.uuid(), name: Matchers.string("Binance"), pairs: Matchers.eachLike({ id: Matchers.uuid(), base: Matchers.like({ id: Matchers.uuid(), name: Matchers.string("Bitcoin"), symbol: Matchers.string("BTC"), }), quote: Matchers.like({ id: Matchers.uuid(), name: Matchers.string("Ethereum"), symbol: Matchers.string("USDT"), }), }), }),```

abatan.k
2021-08-17 02:44
@matt.fellows it seems that my body is interpreted like a hash instead of an array, do you have an hint for this problem ?

abatan.k
2021-08-17 02:44
Im using Matchers.eachLike tho

matt.fellows
2021-08-17 02:45
can you please share the pact file

abatan.k
2021-08-17 02:46
@matt.fellows do you mean the JSON generated by PAct ?

abatan.k
2021-08-17 02:46
Here it is :slightly_smiling_face:

matt.fellows
2021-08-17 02:48
looks ok to me

matt.fellows
2021-08-17 02:48
what?s the verification failure look like now?

abatan.k
2021-08-17 02:50
``` + "name": "Zilliqa", + "symbol": "ZIL" + }, + "quote": { + "id": "9a3a2bfb-522f-4d1c-a766-7eb62147fe80", + "name": "Tether", + "symbol": "USDT" + } + }, + { + "id": "bcf198d0-7342-46d7-995f-e7886097fb9d", + "base": { + "id": "f33e7a5c-b38b-46de-b047-e4bc47366a8a", + "name": "0x", + "symbol": "ZRX" + }, + "quote": { + "id": "9a3a2bfb-522f-4d1c-a766-7eb62147fe80", + "name": "Tether", + "symbol": "USDT" + } + }, + ] + }, +] Description of differences -------------------------------------- * Expected a Hash but got an Array ([{"id"=>"9b685255-2cb8-4f4a-8b41-4f231f78aabc", "name"=>"Binance", "pairs"=>[{"id"=>"42fd3c6e-bfce-429a-b76e-c2d00de68e5b", "base"=>{"id"=>"fe84d516-9336-46a4-a35f-b3e0e7f9140b", "name"=>"Bitcoin", "symbol"=>"BTC"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"2d50f549-07cb-4ca5-8f08-bf3b354c501a", "base"=>{"id"=>"4c49c19a-19b3-42b3-a031-cee8f07e84fa", "name"=>"Ethereum", "symbol"=>"ETH"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"2ebc0d2f-f647-4f13-a983-052aa81eea62", "base"=>{"id"=>"818185aa-d255-40f4-b41d-6291cdda0570", "name"=>"Bitcoin Cash", "symbol"=>"BCH"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"0f27666f-3abb-4808-aa1c-f507a48cb6d8", "base"=>{"id"=>"441ba66a-8747-4885-9096-a143355d1945", "name"=>"XRP", "symbol"=>"XRP"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"ea995e47-9a08-44a9-9815-2ea0b88eace5", "base"=>{"id"=>"d7f4e0c4-8333-47b6-aa41-014e7665bc6e", "name"=>"EOS", "symbol"=>"EOS"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"6d53be8f-c002-43bc-b493-ebe65f858418", "base"=>{"id"=>"e8f71c79-be55-4ec2-a21c-2aee803185f1", "name"=>"Litecoin", "symbol"=>"LTC"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"d0bfbdd7-998e-45a1-bf5f-cf0f001d8147", "base"=>{"id"=>"83c930ae-0a1e-4de3-a4ef-133975e524fa", "name"=>"TRON", "symbol"=>"TRX"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"ca4b3fe8-8cd3-4289-afc5-45ebf300e89d", "base"=>{"id"=>"e39af3cc-9cfc-4070-86d2-568881cc51a0", "name"=>"Ethereum Classic", "symbol"=>"ETC"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"ff8c3828-cc72-41f7-b5cd-89e7f00ca0d3", "base"=>{"id"=>"a7999fef-d03b-4ff8-a385-991bd9d3dc35", "name"=>"Chainlink", "symbol"=>"LINK"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"432d922f-4501-450e-8d00-7d43e441e372", "base"=>{"id"=>"4d3c27b5-e```

abatan.k
2021-08-17 02:50
It says to me that it is expecting a Hash but got an Array

matt.fellows
2021-08-17 02:51
can you please share the full output? You?ve truncated some important part of the logs

abatan.k
2021-08-17 02:56
```? kansu git:(master) ? yarn jest test/contract/fetch-metadata.spec.ts yarn run v1.22.11 warning package.json: No license field $ /home/carere/Projects/ashiso/kansu/node_modules/.bin/jest test/contract/fetch-metadata.spec.ts [2021-08-17 02:54:56.977 +0000] INFO (1978 on carere-silver): pact@9.16.0: Verifying provider [2021-08-17 02:54:56.983 +0000] INFO (1978 on carere-silver): pact-node@10.13.3: Verifying Pacts. [2021-08-17 02:54:56.984 +0000] INFO (1978 on carere-silver): pact-node@10.13.3: Verifying Pact Files FAIL Contract test/contract/fetch-metadata.spec.ts (6.747 s) Pact Verification ? should validate the expectations of Consumer (5003 ms) ? Pact Verification ? should validate the expectations of Consumer thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 11 | }; 12 | > 13 | it("should validate the expectations of Consumer", (done) => { | ^ 14 | new Verifier(opts).verifyProvider().then(() => { 15 | done(); 16 | }); at test/contract/fetch-metadata.spec.ts:13:3 at Object.<anonymous> (test/contract/fetch-metadata.spec.ts:3:1) at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13) at runJest (node_modules/@jest/core/build/runJest.js:387:19) at _run10000 (node_modules/@jest/core/build/cli/index.js:408:7) at runCLI (node_modules/@jest/core/build/cli/index.js:261:3) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 6.805 s, estimated 7 s Ran all test suites matching /test\/contract\/fetch-metadata.spec.ts/i. ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. at Object.getCodec (node_modules/iconv-lite/lib/index.js:65:27) at Object.getDecoder (node_modules/iconv-lite/lib/index.js:127:23) at getDecoder (node_modules/raw-body/index.js:45:18) at readStream (node_modules/raw-body/index.js:180:15) at getRawBody (node_modules/raw-body/index.js:108:12) [2021-08-17 02:55:02.317 +0000] WARN (1978 on carere-silver): pact-node@10.13.3: Pact exited with code 1. (node:1978) UnhandledPromiseRejectionWarning: Error: INFO: Fetching pacts for kansu from https://ashiso.pactflow.io with the selection criteria: latest for tag master INFO: Reading pact at https://ashiso.pactflow.io/pacts/provider/kansu/consumer/uebuapuri/pact-version/fe9c2dd8a04a567f754ec092e9c4ff93f6ac318b/metadata/c1tdW3RdPW1hc3RlciZzW11bbF09dHJ1ZSZzW11bY3ZdPTI5 DEBUG: The pact at https://ashiso.pactflow.io/pacts/provider/kansu/consumer/uebuapuri/pact-version/fe9c2dd8a04a567f754ec092e9c4ff93f6ac318b is being verified because the pact content belongs to the consumer version matching the following criterion: * latest version tagged 'master' (39cd0f5-master) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which equals "application/json; charset=utf-8" (FAILED - 3) Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which has status code 500 (FAILED - 4) has a matching body (FAILED - 5) includes headers "Content-Type" which equals "application/json; charset=utf-8" (FAILED - 6) Failures: 1) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is healthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 2) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is healthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 3) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which includes headers "Content-Type" which equals "application/json; charset=utf-8" Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is healthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 4) Verifying a pact between uebuapuri and kansu Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which has status code 500 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is unhealthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 5) Verifying a pact between uebuapuri and kansu Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is unhealthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 6) Verifying a pact between uebuapuri and kansu Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which includes headers "Content-Type" which equals "application/json; charset=utf-8" Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is unhealthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 2 interactions, 2 failures Failed interactions: * Ashiso's metadata given server is healthy (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="b0c2a8697b51aa6628ecf7cced2c37d3b17f72a4") * Ashiso's metadata given server is unhealthy (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="09f814d10deae36237682ce2425128735fcfb8ca") (Use `node --trace-warnings ...` to show where the warning was created) (node:1978) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:1978) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.```

abatan.k
2021-08-17 02:57
now i get this error, and i don't know how i can prevent the timeout error, i tried to return the promise, i used async / await, i used done callback, but neither of those fix the issue

abatan.k
2021-08-17 02:57
And i know that my request takes 64ms usually, so i don't know how it can go timeout by Jest

matt.fellows
2021-08-17 02:58
3 test runs and 3 different errors - we need to get a consistent set of failures here

matt.fellows
2021-08-17 02:58
how have you increased the timeout?


matt.fellows
2021-08-17 02:59
```--testTimeout 30000```

matt.fellows
2021-08-17 02:59
something like that should work

abatan.k
2021-08-17 03:01
ookkkaaayy i understand now :slightly_smiling_face:

abatan.k
2021-08-17 03:01
the problem comes from my 2nd test, when i check if my server is unhealthy

abatan.k
2021-08-17 03:02
im waiting for an HASH like {error:'...', message:'...'}

abatan.k
2021-08-17 03:02
the first test passes, the second no, that why i get this error

abatan.k
2021-08-17 03:02
the timeout helped me indeed :slightly_smiling_face:

abatan.k
2021-08-17 03:03
thx for the good advice, i'll go back to my code in order to fix this :slightly_smiling_face: sorry if i made you waste some time :sweat_smile: thx for your help, and your availability :slightly_smiling_face:

matt.fellows
2021-08-17 03:04
haha all good

matt.fellows
2021-08-17 03:04
it looks like you?ve either just woken up or have been working a little too hard - either way, get some sleep and/or :coffee: :laughing:

abatan.k
2021-08-17 03:07
haha good advice indeed, but i know why i wa stuck on this, and this is because i was lazy on my TDD, after finishing my command side :sweat_smile: (I'm in a CQRS architecture actually)

abatan.k
2021-08-17 03:07
An i decided to test my consumer with my real implementation instead of my in-memory :slightly_smiling_face:

abatan.k
2021-08-17 03:07
And that's why i got the problem with my timeout ^^

abatan.k
2021-08-17 03:08
because if i was with my inmemeory implementation, it would be blazing fast, and the logs would be shorter

abatan.k
2021-08-17 03:08
So my bad :sweat_smile: im gonna write thoses test for my query side :rolling_on_the_floor_laughing:

matt.fellows
2021-08-17 03:09
yep, definitely easier against local and less issues - why we prefer this over e2e tests!

matt.fellows
2021-08-17 03:09
:raised_hands:

ram.tripathi
2021-08-17 06:33
has joined #pact-js

ricardo.neto
2021-08-17 09:22
has joined #pact-js

andrew.patterson
2021-08-17 14:55
has joined #pact-js

pshah
2021-08-17 15:31
has joined #pact-js

beem132
2021-08-17 17:36
Hello, I'm having issues getting my stateHandlers to run in my provider tests. I'm on V2 of pact-js, I'm attempting to verify a MessageProviderPact, and it gives me a warning saying that it is skipping setup due to no providerStatesUrl being specified. Doing some digging I saw someone else had this issue and the suggestion was that they do something like new Verifier().verifyProvider(opts) to avoid that message, but that particular verifier complains about a missing Url parameter in the options object.

tjones
2021-08-17 23:17
could you share your test code?

dylanchase26
2021-08-18 04:11
has joined #pact-js

satish.chandra
2021-08-18 05:54
has joined #pact-js

flynnhandley
2021-08-18 22:30
has joined #pact-js

beem132
2021-08-19 13:40
hey, thanks for the response, I have no idea what I did but it stopped displaying the warning, I don't think I actually changed any settings, but is it possible the spec value on the messagePact options could have had an impact on the warning?

tjones
2021-08-19 13:48
It's possible, but I think it has to be set to 3 for message pact to work at all (I'm not sure why the option is there)

beem132
2021-08-19 13:50
ah interesting, I think I may have had it set to two and then deleted the property altogether, so that could be it, thanks!

tjones
2021-08-19 13:56
We'll clean that up in the next version, since we have to touch all of those interfaces

tjones
2021-08-19 13:58
At the moment, I believe `new Pact()` must take spec level of 2, and MessagePact must be 3. In the future (if we keep that option), we'll make it warn if you try to set it to things that it can't do

tjones
2021-08-19 13:58
Sorry about that :confused:

beem132
2021-08-19 13:59
No worries, seems like there's quite a bit of good development going on. Spec 2 and Spec 3 are mostly unrelated to the difference between pact 2 and pact 3 right?

paulorochag
2021-08-19 15:01
How can I use the matcher to validate the `new Date()` from the example below? It's a scenario that I haven't found an example. Tried with `[iso8601DateTime(new Date())]` with no success (generated [Object object] )

thomaswtsang
2021-08-19 16:53
has joined #pact-js

brentbarker9
2021-08-19 17:40
karma-pact 3.0.0 and pact-node 10.13.3 appears to be working!

brentbarker9
2021-08-19 17:41
Thanks for your help!

paulorochag
2021-08-19 18:21
@tjones can you help me?

paulorochag
2021-08-19 18:53
I need to validate that the key is of type dateTime, not the value.

chris005
2021-08-19 19:07
has joined #pact-js

abatan.k
2021-08-19 20:40
Hello all :slightly_smiling_face: How do you tests headers ?? For example, i need to match that my header Content-type contains "application/json", but sometimes, the runtime add an extra "charset=UTF-8", do you have best practice for testing headers ??

matt.fellows
2021-08-19 22:30
We don't have key matchers that can check against a regex I don't believe, but we do have a key type matcher

matt.fellows
2021-08-19 22:30
It's available in the v3 beta

thomaswtsang
2021-08-19 22:38
i _think_ you could use `like()` for header matching

matt.fellows
2021-08-19 22:49
I'd use a regex an have an optional group for the charset


abatan.k
2021-08-19 23:25
thx for your answer :slightly_smiling_face:

matt.fellows
2021-08-19 23:27
np!

abatan.k
2021-08-19 23:28
Hey again :slightly_smiling_face: I have some problem with using Pact and my Dependency Injection. Do you also have some best practice for using Pact and DI ? For some context, i using in-memory implementation for my test on the provider side. But i don't think that when i call my API endpoint, the same container is used on both the test context with pact, and the request context. I tried to explain the best i can :sweat_smile: Hope you will understand what i am saying :slightly_smiling_face:

matt.fellows
2021-08-19 23:31
you can?t use an in-memory API, it needs to be available over an actual HTTP port. maybe if you could explain the use case / tech stack a bit more and we can see if we can help?

matt.fellows
2021-08-19 23:32
But basically, before a provider test runs, the provider _must_ have started up and available via HTTP

abatan.k
2021-08-19 23:34
No my API is running, i start my API manually (im using azure function), then im running my tests `yarn jest --testTimeout 30000` . When i say that im using InMemory implementation, im talking about my adapaters (Im using Port & Adapter Architecture / Hexagonal Architecture / Onion / ...)

abatan.k
2021-08-19 23:36
The problem is that when im populating my inmemory repositories on my provider test, my API doesn't seems to use the same instance of my repositories, so i cannot validate my tests

tjones
2021-08-19 23:37
Hmm. This sounds like a test setup problem rather than a pact problem

tjones
2021-08-19 23:37
(also I like your design choices, this is what I do too :+1:)

abatan.k
2021-08-19 23:38
yeah im a lot in craftmanship :slightly_smiling_face: im using CQRS with hexagonal architecture and some DDD concept, like Bounded Context, etc :wink:

abatan.k
2021-08-19 23:38
and im french so, sorry for my english :rolling_on_the_floor_laughing:

tjones
2021-08-19 23:38
It's not problem, your question is clear

abatan.k
2021-08-19 23:39
To clarify, im noy saying that there is any problem with Pact, i know that my problem comes from my DI lib / implementaion. And since your using Pact in production, i guess you guys, also use some DI implementation in your code base

tjones
2021-08-19 23:41
Yes. In JS, I usually roll my own DI with default params

tjones
2021-08-19 23:43
for example, in a repository I'm working on at the moment, config is loaded asynchronously. So, the file that creates the API reads like: ```export const apiClientFactory = ( tenant: string, configPromise: Promise<ApiConfig> = CONFIG,```

tjones
2021-08-19 23:43
oh, sorry, you're looking at the provider

tjones
2021-08-19 23:44
I use a similar pattern for the provider, but I don't have an example easily to hand

tjones
2021-08-19 23:44
The symptom you have sounds like you might be injecting into a different instance of the app than you're testing?

abatan.k
2021-08-19 23:44
ok i guess i just should use a simple object for my DI container

abatan.k
2021-08-19 23:45
and not rely on third party lib for handling DI

tjones
2021-08-19 23:45
You don't have to - I just find it easy to do it that way

tjones
2021-08-19 23:46
hold on, got a meeting, I'll be back in a bit to elaborate

abatan.k
2021-08-19 23:47
Yeah, but i think im using a lib for DI, because im used to do this in other langage, (im coming from PHP). But it seems that in JS, we don't really need to use 3rd-Party lib, for such simple pattern.

matt.fellows
2021-08-19 23:47
I?ve never really seen a good need for DI frameworks in JS.

matt.fellows
2021-08-19 23:48
It feels like at the point you do that, you may as well just use Java/.NET :stuck_out_tongue:

tjones
2021-08-19 23:48
> I?ve never really seen a good need for DI in JS. Really? I do it in every project

matt.fellows
2021-08-19 23:48
(that?s my opinion, I know DI framewoks exist)

matt.fellows
2021-08-19 23:48
I just updated my answer, I meant DI *frameworks*

abatan.k
2021-08-19 23:50
@matt.fellows honestly im starting thinking the same as you, it is not a langage like PHP / C# / JAVA, and it also seems that the `import / export` capability of JS is enough for DI.

abatan.k
2021-08-19 23:52
So do you have best practice for handling your DI _*without*_ using DI framework ?? I thought about a simple object, where i instantiating in memory adapter and real adapter depending some NODE env variable

abatan.k
2021-08-20 00:24
Ok after some thoughts, i found the problem. In order to run my (azure) functions, i need to compile my typescript, so, my functions use the `dist` folder which is generated by `tsc` . And my tests are using ts-jest in order to run.

srimuralixi
2021-08-20 02:18
has joined #pact-js

tjones
2021-08-20 04:55
Ah yeah. That can be a problem.

tjones
2021-08-20 04:55
I'll update with some thoughts on DI in JS later.

manika.goel
2021-08-20 05:38
has joined #pact-js

manika.goel
2021-08-20 06:18
When I do npm run publish, I am getting error as "No value provided for required options '--broker-base-url'" I tried clearing the cache and installing npm, tried upgrading npm version to 7.21.0. I am still getting this issue. Can someone please help me out here, I am kind of stuck because of this.

matt.fellows
2021-08-20 06:18
have you provided the broker details?

matt.fellows
2021-08-20 06:19
looks pretty clear to me, you?re not passing the broker details

manika.goel
2021-08-20 06:19
yes set PACT_BROKER_BASE_URL=https://centricconsulting.pactflow.io

manika.goel
2021-08-20 06:19
and its token as well

matt.fellows
2021-08-20 06:19
did you set it in that shell?

manika.goel
2021-08-20 06:21
I created this in PACT account and from there I copied my API token

manika.goel
2021-08-20 06:21
Do I need to set it somewhere as well?

matt.fellows
2021-08-20 06:22
it looks like that?s a powershell terminal

matt.fellows
2021-08-20 06:22
```$env:PACT_BROKERBASE_URL=...```

matt.fellows
2021-08-20 06:23
I could be wrong, but it looks like the environment variable is not properly propagating to the shall

matt.fellows
2021-08-20 06:23
you can pass it directly to the publish command also

manika.goel
2021-08-20 06:24
ok let me try this

manika.goel
2021-08-20 06:26
"scripts": {     "test:consumer": "mocha --exit --timeout 30000 consumer.pact.spec.js",     "test:provider": "mocha --exit --timeout 30000 provider.pact.spec.js",     "publish": "npx pact-broker publish ./pacts --consumer-app-version 1.0.0-someconsumersha --tag master"   }, Here you are asking me to mention the env variables? Any example how to do that?

matt.fellows
2021-08-20 06:27
can you please demonstrate that the environment variables are indeed active in your terminal?

matt.fellows
2021-08-20 06:27
if it?s the batch shell, just run `set` and check that the environment variables are set

matt.fellows
2021-08-20 06:28
if powershell: ```gci env:* | sort-object name```

akanksha.sharma
2021-08-20 06:31
has joined #pact-js

manika.goel
2021-08-20 06:36
I am getting this on running this command

matt.fellows
2021-08-20 06:36
I don?t see any PACT_ variables there

matt.fellows
2021-08-20 06:36
you need to set them using Powershell

manika.goel
2021-08-20 06:37
can you please provide an example how to do that?


manika.goel
2021-08-20 06:40
PS C:\ContractTesting_POC> set env:PACT_BROKERBASE_URL=https://centricconsulting.pactflow.io PS C:\ContractTesting_POC> set env:PACT_BROKER_TOKEN=Kel0T09C4jmBPo1QevJaNA tried this, still not seeing PACT_ variables

matt.fellows
2021-08-20 06:41
You don?t use set, you need the $ also

matt.fellows
2021-08-20 06:41
```$env:PACT_BROKER_BASE_URL="https://centricconsulting.pactflow.io"```

matt.fellows
2021-08-20 06:41
```#env:PACT_BROKER_TOKEN=Kel0T09C4jmBPo1QevJaNA```

matt.fellows
2021-08-20 06:42
*now, because this is in public, please go and reset your credentials in Pactflow before your account is taken over* :wink:

manika.goel
2021-08-20 06:46
Got this PACT_ variable but still getting same issue on executing npm run publish: "No value provided for required options '--broker-base-url'"

matt.fellows
2021-08-20 06:46
check the spelling

matt.fellows
2021-08-20 06:46
```PACT_BROKER_BASE_URL``` not ```PACT_BROKERBASE_URL```

manika.goel
2021-08-20 07:10
Thanks Matt. It worked

manika.goel
2021-08-20 07:33
PS C:\ContractTesting_POC> $env:PACT_BROKER_BASE_URL="https://centricconsulting.pactflow.io/" PS C:\ContractTesting_POC> #env:PACT_BROKER_TOKEN=<token> PS C:\ContractTesting_POC> npm run publish > pactflow-getting-started-js@0.1.0 publish > npx pact-broker publish ./pacts --consumer-app-version 1.0.0-someconsumersha *Publishing poc-consumer/poc-provider pact to pact broker at https://centricconsulting.pactflow.io/* *Failed to publish poc-consumer/poc-provider pact due to error: PactBroker::Client::Error - Authentication failed: Unauthorized. Please see https://docs.pactflow.io/docs/login-help for more information.* One or more pacts failed to be published I am getting Authentication failed error although I am able to login the url mentioned.

manika.goel
2021-08-20 07:34
I have tried clearing cache, updating pact version, taken read/write API token

matt.fellows
2021-08-20 07:35
your token command looks wrong

matt.fellows
2021-08-20 07:35
it?s prefixed with a `#`

matt.fellows
2021-08-20 07:35
It worked before, so always suspect it?s your local environment setup

manika.goel
2021-08-20 07:40
```#env:PACT_BROKER_TOKEN=Kel0T09C4jmBPo1QevJaNA``` I provided like you mentioned before

matt.fellows
2021-08-20 07:41
no, it should be `$env:` but you used `#env:`

matt.fellows
2021-08-20 07:41
if you can?t remember, google ?how to set env var in powershell?

manika.goel
2021-08-20 07:42
got it. Thanks

manika.goel
2021-08-20 07:42
it worked

manika.goel
2021-08-20 07:42
:slightly_smiling_face:

tjones
2021-08-20 08:47
what do you mean by pact 2 and pact 3?

tjones
2021-08-20 08:47
`spec` is the "pact specification version"

abatan.k
2021-08-20 10:15
I decided to go with a local web server for my contract testing instead of launching azure function. Since what i do is testing a function :sweat_smile:

matt.fellows
2021-08-20 10:40
sorry, got sidetracked - but that?s _exactly_ what you should do!

akanksha.sharma
2021-08-20 10:48
Need one information related to pact provider side, if I need to connect to my real time provider, what and where we should provide the changes?

tjones
2021-08-20 11:38
What changes?


akanksha.sharma
2021-08-20 11:40
Sure


akanksha.sharma
2021-08-20 12:29
should I change in the below code to access our own project api's (swagger links). ```server.listen(8081, () => {  importData()  console.log("Animal Profile Service listening on http://localhost:8081") })```

akanksha.sharma
2021-08-20 12:32
Also, I am not able to access this url from my local machine then how I am getting a valid response ```http://localhost:8081``` Just need clarification


matt.fellows
2021-08-20 12:42
Looks like we need to add to those docs sorry!

paulorochag
2021-08-20 12:42
Thank you

jonah
2021-08-20 14:42
has joined #pact-js

tlzhou
2021-08-20 15:02
has joined #pact-js

rsaccoll
2021-08-20 17:51
has joined #pact-js

abatan.k
2021-08-20 18:33
yeah it's way more simple :slightly_smiling_face:, anyway thx for the discussion, it helps me a lot :wink:

abatan.k
2021-08-20 18:35
@akanksha.sharma Can you launch a local web server ? (eg. `http.createServer`)

abatan.k
2021-08-20 18:36
I asked the same question as you yesterday, since im using Azure function, and the best approach it's to launch your local server for verifying contract on provider side

abatan.k
2021-08-20 18:39
This is what i do for example, hope it's help :wink:

matt.fellows
2021-08-21 10:29
Not sure I understand your question Akshanka

matt.fellows
2021-08-21 10:29
You need to have the code available for the provider code base locally, start the service locally and test it locally. That?s how 99% of pact provider verifications should happen

matt.fellows
2021-08-21 10:30
> should I change in the below code to access our own project api?s (swagger links). swagger links? The example you provided starts a locally express JS server and then below in the test it tests against that service. What do yo umean by swagger links?

ramya.sri
2021-08-23 03:52
has joined #pact-js

akanksha.sharma
2021-08-23 06:20
from swagger links I mean to say the url of swagger documents where all our API's are listed for project

akanksha.sharma
2021-08-23 06:22
Okay I am going to setup local system so that I can start service locally with help of developer, till now I am only able to access dev and QA env of my project

akanksha.sharma
2021-08-23 06:35
The question I previously want to ask is : I setup the code base locally in VS code for katacoda (https://katacoda.com/pact/scenarios/pactflow-getting-started-js) to get an idea how I can do it for my real time project. Now, in katacoda in provider code, the base url is mentioned as ```providerBaseUrl: "http://localhost:8081"``` and this localhost:8081 is not setup locally on my system but I am still able to verify the pact. So, how the code is connected to the server from my local as I am not able to access localhost:8081 and getting a valid response. I hope you understand it now

matt.fellows
2021-08-23 07:14
Are you asking how katacoda is working when it points to localhost:8081? It works because it?s running on remove Katacoda infrastructure, not your machine

matt.fellows
2021-08-23 07:14
The test is running on remote servers, and it?s starting up an app on those same servers, hence it?s ?local? (localhost) to to where the test is running

matt.fellows
2021-08-23 07:15
> Okay I am going to setup local system so that I can start service locally with help of developer, till now I am only able to access dev and QA env of my project I?m not trying to discourage you, but Pact testing is very much a tool that requires strong technical knowledge, the ability to write and maintain unit tests and good comprehension of the unit you are testing.

matt.fellows
2021-08-23 07:15
Doing Pact ?from the outside? as a black-box style test is not really possible

matt.fellows
2021-08-23 07:16
If I understand correctly, you have a Pactflow account, so you could look at using the Pactflow https://docs.pactflow.io/docs/workshops/bi-directional feature if the above requirements aren?t met

joseramonrivera21
2021-08-23 08:49
has joined #pact-js

denny.duttig
2021-08-23 10:10
has joined #pact-js

akansha.saraswat3
2021-08-23 10:50
has joined #pact-js

dimundo
2021-08-23 18:23
hi! i?m, getting > Could not parse the following content to a Pact due to Pact::UnrecognizePactFormatError and > pact@9.16.0: no handler found for message common.signal still json is valid and looks okish ( for the 1st error ) and description presents ( for the 2nd ) any ideas ?

tjones
2021-08-23 20:51
Is this a pact generated with pact spec version 3?


dimundo
2021-08-23 21:01
issue is, that i wanted to split 1 provider into 2, for 2 consumers

dimundo
2021-08-23 21:01
and looks like it was bad idea

dimundo
2021-08-23 21:03
so separated message triggered `no handler found for message`

sushant.soni
2021-08-23 21:10
has joined #pact-js

dimundo
2021-08-23 21:13
but there is sideeffect of that - build not failed :scream_cat: will investigate tomorrow

tjones
2021-08-23 22:46
pact-js doesn't support spec version 3 yet

tjones
2021-08-23 22:47
we're working on that release

tjones
2021-08-23 22:47
if you like, you can try the beta version


dimundo
2021-08-24 05:40
> pact-js doesn?t support spec version 3 yet weird, pactbroker says, that generated jsons are v3

ajaiswal595
2021-08-24 11:00
has joined #pact-js

pd287515778
2021-08-24 12:48
has joined #pact-js

hwebster
2021-08-25 05:30
has joined #pact-js

hoangvo
2021-08-25 05:43
has joined #pact-js

jobjingjo
2021-08-25 06:20
has joined #pact-js

vbhardwaj.eminent
2021-08-25 07:01
hi, Can I pass tags like this from jenkins so that it can be attached to the pact on pact broker ```Global.script.sh(script: "cd ./client && CI=true tags=${getBranchName()} npm run test:pact -- ${versionId}")``` I could see that in jenkins steps that tags are sent fine from jenkins but not published on the pact in pact broker

tjones
2021-08-25 07:01
I'm not sure I understand what you're trying to do

tjones
2021-08-25 07:02
this looks like it's setting an environment variable called `tags`? Pact doesn't read this variable. Does your script read it?

tjones
2021-08-25 07:02
Also, the verifier supports this specific feature out of the box:

vbhardwaj.eminent
2021-08-25 07:02
in pact js workshop tags are hardcoded in publish.pact.js, but I want to attach my branch name as tag to the contract

tjones
2021-08-25 07:03
Right, we should update that.

tjones
2021-08-25 07:03
It's better practice just to call the publish binary:

vbhardwaj.eminent
2021-08-25 07:03
could you give an example

vbhardwaj.eminent
2021-08-25 07:03
how to do it

tjones
2021-08-25 07:04
``` "pact:publish": "pact-broker publish pacts --consumer-app-version=\"$(npx @pact-foundation/absolute-version)\" --tag-with-git-branch --broker-base-url=https://pact-broker.example.com"```

tjones
2021-08-25 07:05
this is a (slightly redacted) example from one of my projects

tjones
2021-08-25 07:05
Note that this assumes that your pacts are in a directory called `pacts`

tjones
2021-08-25 07:06
I'd like to go through all the examples and remove `publish.js`

tjones
2021-08-25 07:06
it's not necessary and I think it causes more confusion than it helps

vbhardwaj.eminent
2021-08-25 07:08
why

tjones
2021-08-25 07:08
because you can get the publish functionality directly from your npm script

vbhardwaj.eminent
2021-08-25 07:11
can i do `"posttest:pact": "node publish.pact.js --tag-with-git-branch"`

matt.fellows
2021-08-25 07:29
does the file `publish.pact.js` accept that argument? If you?ve copied from one of the Pact JS examples, I doubt it

matt.fellows
2021-08-25 07:30
`publish.pact.js` is a user defined piece of JS, that essentially delegates back to the command Tim is referring to. So you can do whatever you want in that, and you could make your example work

vbhardwaj.eminent
2021-08-25 07:30
I got it

matt.fellows
2021-08-25 07:30
But FWIW I would just use the CLI directly. Less code, something you can repeat across languages for consistency etc.

vbhardwaj.eminent
2021-08-25 07:30
thanks Matt and Tim!

matt.fellows
2021-08-25 07:31
:thumbsup:

matt.fellows
2021-08-25 07:31
np

sagarsitap596
2021-08-25 14:10
has joined #pact-js

kyle.fischer
2021-08-25 16:31
has joined #pact-js

datasmithadvtech
2021-08-25 19:43
has joined #pact-js

todor.m.kolev
2021-08-25 19:59
has joined #pact-js

sushmitha.amin
2021-08-26 04:31
has joined #pact-js

tausif2909
2021-08-26 06:00
Hello, At consumer side my path contains the uuid : `"path": "/api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c"` , How do I replace the uuid in providerVerification code, Can someone share the example?

matt.fellows
2021-08-26 06:56
you would usually have a provider state that says `given a secret with uuid 4gf8c91a-64e1-47c2-a293-72252b5c1e4c exists` and a state handler that can create the secret

matt.fellows
2021-08-26 06:56
i.e. provider states


tausif2909
2021-08-26 07:18
Thanks @matt.fellows

akansha.saraswat3
2021-08-26 11:11
Hey team, I am getting the following error after running the pact.spec file ```thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 10 | 11 | describe('Retrieving Project Details', () => { > 12 | beforeAll(() => mockProvider.setup()); | ^ 13 | beforeEach(() => { 14 | jest.setTimeout(90000); 15 | });```

matt.fellows
2021-08-26 11:13
Try adding a global timeout as a flag in jest. Also, what do the debug logs say? Have a look at the section on troubleshooting

shwetastar98
2021-08-26 12:35
has joined #pact-js

contact
2021-08-26 12:44
has joined #pact-js

tjones
2021-08-26 13:17
BeforeAll is executed before beforeEach, so your timeout isn?t being set

tjones
2021-08-26 13:17
You can use jest-pact to set all the right defaults for pact, and to reduce the boilerplate

malena.cadima
2021-08-26 16:07
has joined #pact-js

louis.ss
2021-08-27 01:42
has joined #pact-js

akansha.saraswat3
2021-08-27 05:08
@malena.cadima These are the logs--- couldn't get much out of it. Can you pls check? ```0 info it worked if it ends with ok 1 verbose cli [ 1 verbose cli '/usr/local/bin/node', 1 verbose cli '/usr/local/bin/npm', 1 verbose cli 'run', 1 verbose cli 'coverage', 1 verbose cli '--', 1 verbose cli '-u', 1 verbose cli 'src/__tests__/components/project-search/projectsearch.pact.spec.js' 1 verbose cli ] 2 info using npm@6.14.4 3 info using node@v14.2.0 4 verbose run-script [ 'precoverage', 'coverage', 'postcoverage' ] 5 info lifecycle grand-ui-core@1.0.0~precoverage: grand-ui-core@1.0.0 6 info lifecycle grand-ui-core@1.0.0~coverage: grand-ui-core@1.0.0 7 verbose lifecycle grand-ui-core@1.0.0~coverage: unsafe-perm in lifecycle true 8 verbose lifecycle grand-ui-core@1.0.0~coverage: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/a0s0dw5/Documents/GitHub/grand-ui-core/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/a0s0dw5/Documents/GitHub/grand-ui-core/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin 9 verbose lifecycle grand-ui-core@1.0.0~coverage: CWD: /Users/a0s0dw5/Documents/GitHub/grand-ui-core 10 silly lifecycle grand-ui-core@1.0.0~coverage: Args: [ 10 silly lifecycle '-c', 10 silly lifecycle 'CI=true react-scripts --max_old_space_size=4096 test --ci --coverage --testResultsProcessor=./node_modules/jest-sonar-reporter --env=jest-environment-jsdom-sixteen "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js"' 10 silly lifecycle ] 11 silly lifecycle grand-ui-core@1.0.0~coverage: Returned: code: 1 signal: null 12 info lifecycle grand-ui-core@1.0.0~coverage: Failed to exec coverage script 13 verbose stack Error: grand-ui-core@1.0.0 coverage: `CI=true react-scripts --max_old_space_size=4096 test --ci --coverage --testResultsProcessor=./node_modules/jest-sonar-reporter --env=jest-environment-jsdom-sixteen "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js"` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:315:20) 13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:315:20) 13 verbose stack at maybeClose (internal/child_process.js:1051:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) 14 verbose pkgid grand-ui-core@1.0.0 15 verbose cwd /Users/a0s0dw5/Documents/GitHub/grand-ui-core 16 verbose Darwin 19.6.0 17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "coverage" "--" "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js" 18 verbose node v14.2.0 19 verbose npm v6.14.4 20 error code ELIFECYCLE 21 error errno 1 22 error grand-ui-core@1.0.0 coverage: `CI=true react-scripts --max_old_space_size=4096 test --ci --coverage --testResultsProcessor=./node_modules/jest-sonar-reporter --env=jest-environment-jsdom-sixteen "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js"` 22 error Exit status 1 23 error Failed at the grand-ui-core@1.0.0 coverage script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]```

tjones
2021-08-27 05:08
This is not the pact log

tjones
2021-08-27 05:09
The pact log will be in the `log` directory by default, or `pact/log` if you're using jest-pact. Or wherever you've configured it if you have changed it

tjones
2021-08-27 05:10
Did you try moving the setting of the timeout to your `beforeAll`?

tjones
2021-08-27 05:11
Although, that error log looks like you're having a problem with the coverage script, which will be unrelated to pact.

akansha.saraswat3
2021-08-27 05:20
yes i did .... i used beforeAlll earlier, error was still the same - timeout. I'll check for pact log and post here

akansha.saraswat3
2021-08-27 06:38
Where do we set this global variable? and what is global variable name and format to set?

akansha.saraswat3
2021-08-27 06:51
I am unable to move further from this .... every time I run test case... this error comes in ``` thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 20 | 21 | }); > 22 | beforeAll(() => mockProvider.setup()); | ^ 23 | test('ID 112342-001', async () => { 24 | const expectedProduct = { 25 | "status": "success",``` Code Snippet ```describe('Retrieving Project Details', () => { beforeEach(() => { jest.setTimeout(jestConfig.defaultTimeoutInterval || 15000); }); beforeAll(() => mockProvider.setup()); test('ID 112342-001', async () => { const expectedProduct = { "status": "success", "message": null,```


matt.fellows
2021-08-27 06:53
(from our workshop)

matt.fellows
2021-08-27 06:54
what is the value of `jestConfig.defaultTimeoutInterval` ?

matt.fellows
2021-08-27 06:54
presumably, 5000ms

akansha.saraswat3
2021-08-27 06:54
yes default value

matt.fellows
2021-08-27 06:54
What are you expecting `jest.setTimeout(jestConfig.defaultTimeoutInterval || 15000);` to do?

matt.fellows
2021-08-27 06:56
This is a question about *Jest*, your test runner. I?ve given an example, but I?d be googling Jest docs for more on htat

akansha.saraswat3
2021-08-27 06:58
it's just a different way to write timeout ... just to see if this will work .. earlier i just used the time unit

matt.fellows
2021-08-27 06:59
well, that statement says set the timeout value to `15000` _only if_ there is no default timeout. Which I think is why your timeout isn?t overriding the default timeout - there is a default, and it?s `5000`!

akansha.saraswat3
2021-08-27 07:00
yeah i don't see t anywhere in the code and how to override it. No matter what i do ... the default timeout is not getting replaced


akansha.saraswat3
2021-08-27 07:34
This didn't solve the problem, same 5000ms jest timeout issue. Could you pls check how to replace this default timeout for jest? Any example frameworks if you have

matt.fellows
2021-08-27 07:35
rather than us continually try ways to tweak your code that we can?t see, perhaps you could create a reproducable example we can help with? The timeout is a jest property, and this is a Pact forum

tjones
2021-08-27 07:37
You can also use `jest-pact`, which sets the timeout for you.


sergio.amorim
2021-08-27 14:40
has joined #pact-js

slin
2021-08-29 23:51
has joined #pact-js

shane.robinson
2021-08-30 00:30
has joined #pact-js

br.maher
2021-08-30 04:35
has joined #pact-js

akanksha.sharma
2021-08-30 11:04
Quick question - Does pact also verify the value of data present in response body OR it only verify the datatype of the fields present in response body. For eg : "body": {           "accountId": 9348878860,           "agencyCode": "5678777",           "accountStatus": "Open"} I want to validate agencyCode as negative scenario, value "5678777" should not match with provider value. So creating a mock API with "agencyCode": "5678777", but my provider has "agencyCode": "4218". When I am running my test, I am expecting it to get failed but its still passing.

matt.fellows
2021-08-30 11:13
yes, it will match exact values if you tell it to

matt.fellows
2021-08-30 11:13
if you?re using a matcher e.g. `Matchers.like` then it just looks at the type

akanksha.sharma
2021-08-30 11:19
What is the matcher function to match the exact values?

matt.fellows
2021-08-30 11:25
you don?t use a matcher

akanksha.sharma
2021-08-30 11:31
Then ?

matt.fellows
2021-08-30 11:33
you just don?t use a matcher, and it will use the value you provided

matt.fellows
2021-08-30 11:33
maybe share what you?re doing so we can advise?

akanksha.sharma
2021-08-30 11:38
consumer.pact.spec.js

akanksha.sharma
2021-08-30 11:38
please check below code

akanksha.sharma
2021-08-30 11:41
```const { Pact } = require ('@pact-foundation/pact'); const { ProductApiClient } = require ('./api'); const { Product } = require ('./product'); const { Matchers } = require("@pact-foundation/pact") const { like, regex } = Matchers const chai = require("chai") const expect = chai.expect // (2) Configure our Pact library const mockProvider = new Pact({   consumer: 'account-consumer_v5',   provider: 'account-provider_v5',   cors: true  }); describe('Account API test', () => {   // (3) Setup Pact lifecycle hooks   before(() => mockProvider.setup());   afterEach(() => mockProvider.verify());   after(() => mockProvider.finalize());   it('get account by ID', async () => {     // (4) Arrange     const expectedProduct = { accountId: 9348878860, agencyCode: "4218", accountStatus: "Open" }     await mockProvider.addInteraction({       state: 'an account with ID 9348878860 exists',       uponReceiving: 'a request to get an account',       withRequest: {         method: 'GET',         path: '/v1/accounts/9348878860'       },       willRespondWith: {         status: 200,         headers: {           'Content-Type': regex({generate: 'application/json; charset=utf-8', matcher: '^application\/json'}),         },         body: like(expectedProduct),       },     });     // (5) Act     const api = new ProductApiClient(mockProvider.mockService.baseUrl);     console.log("Base url : " + mockProvider.mockService.baseUrl)     const product = await api.getAccount(9348878860);     // (6) Assert that we got the expected response     expect(product).to.deep.equal(new Product(9348878860, "4218", "Open"));   }); });```

matt.fellows
2021-08-30 11:41
`like(expectedProduct)` So this says ?match every single property in the object based on its type, and not the value?

matt.fellows
2021-08-30 11:42
rather than wrapping the whole object in a `like` just wrap the properties you want to match by type

kwongyun
2021-08-30 15:57
has joined #pact-js

0x06065a
2021-08-31 00:02
has joined #pact-js

matt.thomas
2021-08-31 05:29
has joined #pact-js

abhi.nandan964
2021-08-31 10:19
has joined #pact-js

tausif2909
2021-08-31 11:53
Hi, To write `matcher` for an `id` in `path` I have found : `path: term({ generate: "/animals/1", matcher: "/animals/[0-9]+" })` , Same way how can we write the regex matcher for `uuid` ?

tjones
2021-08-31 11:55
Are you asking for a regex for a standard uuid like `123e4567-e89b-12d3-a456-426614174000`?

tjones
2021-08-31 11:56
try: ```[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}```

tausif2909
2021-08-31 12:16
Thanks @tjones

tausif2909
2021-08-31 12:30
Sorry but that didn't work

tausif2909
2021-08-31 12:30
Is this the right way to write in `path`

tausif2909
2021-08-31 12:31
`path: term({ generate: '/api/accounts/4gf8c91a-64e1-47c2-a293-72252b5c1e4c', matcher: '/api/accounts/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}' })`

abubics
2021-08-31 12:47
what about it isn't working?

abubics
2021-08-31 12:48
in Kotlin, I've got ```matchPath( "/admin/amendments/${RegexUUID}", "/admin/amendments/${ConstUUID}" )``` where ```private const val Hex = "[0-9a-fA-F]" private const val RegexUUID = "${Hex}{8}-${Hex}{4}-${Hex}{4}-${Hex}{4}-${Hex}{12}"```

abubics
2021-08-31 12:49
so I guess you could do a similar thing in JS.

abubics
2021-08-31 12:49
Do you get an error, or something?

tausif2909
2021-08-31 12:50
its not generating the pact, no error in logs, It works fine when I replace the regex to `[0-9]+`

tausif2909
2021-08-31 13:34
It works with simple regex like `[0-9a-f]` but if I add something in `{}` like `[0-9a-f]{12}` It doesn't generate the pact file

abubics
2021-08-31 13:47
I don't know if you need to escape the `-`s . . . which logs have you looked in? Usually, if the pactfile doesn't get generated, there'll be logs saying what went wrong (e.g. in `./logs/`)

abubics
2021-08-31 13:50
there also should be a `uuid` matcher, you could check how it works, and replicate that in your URL

shivi.btech08
2021-08-31 21:03
has joined #pact-js

tausif2909
2021-09-01 04:59
tried `uuid` matcher too.. that didn't work :disappointed:

abubics
2021-09-01 06:22
it's a bit hard to help if all the information given is "it didn't work" :pray:

tausif2909
2021-09-01 06:50
When I use normal regex like : `[0-9a-zA-Z]+` it generates logs in log file like below :

tausif2909
2021-09-01 06:50
```I, [2021-09-01T11:35:09.929594 #17936] INFO -- : Registered expected interaction GET /api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c D, [2021-09-01T11:35:09.929594 #17936] DEBUG -- : { "description": "Get secrets by UUID", "request": { "method": "GET", "path": { "json_class": "Pact::Term", "data": { "generate": "/api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "matcher": { "json_class": "Regexp", "o": 0, "s": "/api/secrets/[0-9a-zA-Z]+" } } }, "query": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "uuid": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "revision": { "json_class": "Pact::SomethingLike", "contents": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c" }, "data": { "key": "AKIAJXZAXSMEXIGSGPNA", "secret": "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", "flexVideoProxyPact": "true" }, "lastUpdate": { "json_class": "Pact::SomethingLike", "contents": 1584542499435 } } }, "metadata": null } I, [2021-09-01T11:35:09.944560 #17936] INFO -- : Received request GET /api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c D, [2021-09-01T11:35:09.944876 #17936] DEBUG -- : { "path": "/api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "query": "", "method": "get", "headers": { "Accept": "application/json", "User-Agent": "Needle/2.9.0 (Node.js v14.17.1; win32 x64)", "Host": "localhost:18186", "Connection": "close", "Version": "HTTP/1.1" } } I, [2021-09-01T11:35:09.945057 #17936] INFO -- : Found matching response for GET /api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c D, [2021-09-01T11:35:09.945057 #17936] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "uuid": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "revision": { "json_class": "Pact::SomethingLike", "contents": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c" }, "data": { "key": "AKIAJXZAXSMEXIGSGPNA", "secret": "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", "flexVideoProxyPact": "true" }, "lastUpdate": { "json_class": "Pact::SomethingLike", "contents": 1584542499435 } } } I, [2021-09-01T11:35:09.959953 #17936] INFO -- : Writing pact for flex-secrets-service to D:/git-directory/flex-videoproxy-service/pact/flex-videoproxy-service-flex-secrets-service.json```

tausif2909
2021-09-01 06:51
but when I use regex for uuid, the log file remain empty

tausif2909
2021-09-01 06:51
Thats why I dont have any more information to share

kpuengpanich
2021-09-01 07:14
has joined #pact-js

mhmtyuceoz
2021-09-01 07:35
has joined #pact-js

tausif2909
2021-09-01 09:35
nevermind, I have switched to pactV3, and got the expected output, thanks for your help @abubics

abubics
2021-09-01 09:44
oh cool, I'm glad you got something working!

tjones
2021-09-01 11:04
I suspect that there was something else in the test that was causing the failure, like a promise not being returned to the testing framework

tjones
2021-09-01 11:05
But if it?s working now with v3, that?s good

tausif2909
2021-09-01 11:28
Yeah it worked with V3, But I have changed the approach, instead of using `term`, I have used `MatchersV3.fromProviderState`

tausif2909
2021-09-01 13:24
Hi, After upgrading to `V3` , Publish to Pact Broker is broken, Getting error : `Error: Cannot find module '@pact-foundation/pact-node'` Previously I was on version `9.16.0`, What changes are required, Can someone share the example

tjones
2021-09-01 13:28
Where are you getting this error?

tjones
2021-09-01 13:31
It?s much easier to help you if you can share your test code- I think your other example could have been solved that way

tjones
2021-09-01 13:31
If you are including pact-node in your test, then you?ll need to use pact-core instead in the beta branch

tjones
2021-09-01 13:32
But, you shouldn?t need to include either- you can publish straight from the pact-broker command

tjones
2021-09-01 13:32
I?m on mobile right now but I can link you to the documentation tomorrow

tjones
2021-09-01 13:33
To make it easiest for us to help you, have a look at howtoask

2021-09-01 13:33
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help

tausif2909
2021-09-01 13:38
I have replaced `@pact-foundation/pact-node` with `@pact-foundation/pact-core` looks like it worked

tjones
2021-09-01 14:06
Make sure you pin the version of both pact-core and pactjs-beta. The interface is not stable and will change.

volkan.tufekci
2021-09-02 08:47
has joined #pact-js

yassine
2021-09-02 10:59
has joined #pact-js

connor.beck
2021-09-02 13:39
has joined #pact-js

maurits.out
2021-09-02 15:12
has joined #pact-js

kumasaka.tk
2021-09-02 21:24
has joined #pact-js

valeriia.danylenko
2021-09-03 18:26
has joined #pact-js

irmt06
2021-09-04 22:51
has joined #pact-js

aram
2021-09-05 06:50
Hi folks, need some assistance :slightly_smiling_face: At the moment, due to difficulties, i?m running contract test as Integration. So we?re writing a DELETE test, and for that i need to first create (on provider side) the object, which is given a unique ID. How can i add that ID to the url on the _provider_ side?

tjones
2021-09-05 06:52
In the current release of pact-js, you can't. You have to mock the thing that creates a unique ID

tjones
2021-09-05 06:52
however, in the upcoming release, you will be able to use provider state variables

tjones
2021-09-05 06:52
you can check this out with the beta branch (see under V3 pacts in the readme)

tjones
2021-09-05 06:53
however, note that the interface for that branch is in flux and will change

aram
2021-09-05 06:55
Sounds great, thanks @tjones? i?ll follow the release :slightly_smiling_face:

tjones
2021-09-05 06:55
Oh, actually, you may have another option. There's the ability to modify the request before it is sent to the provider. I'm not sure if you can modify the URL though. See: https://github.com/pact-foundation/pact-js#modify-requests-prior-to-verification-request-filters

aram
2021-09-05 06:57
i think this if just for the headers. I want to change the request URL for a specific pact test..

tjones
2021-09-05 07:05
Yeah. You might be able to subvert that mechanism, though. The way it is implemented is that the request goes through a proxy, and this is a filter in the proxy. You have access to the full request object. However, the proxy doesn't respect all changes.

tjones
2021-09-05 07:05
Which pact framework is the consumer test in?

aram
2021-09-05 07:08
js as well

tjones
2021-09-05 07:10
Cool. This isn't well documented, but the request filter is express app-level middleware. A quick read of their docs suggests that you can change the path:


aram
2021-09-05 07:11
hmm?. i?ll take a look. Thanks again

tjones
2021-09-05 07:11
In summary, you have three options: ? use provider state to mock the unique identifier so the client can know it ? use pact-js 10.x beta (but the interface will change) ? use a request filter, but it's a bit of a hack

tjones
2021-09-05 07:11
The highest priority is releasing the next version of pact-js with all this support.

tjones
2021-09-05 07:11
(for us)

aram
2021-09-05 07:12
any ETA on that?

tjones
2021-09-05 07:12
If you go the beta, make sure you pin the version

tjones
2021-09-05 07:12
Unfortunately not really. Both Matt and I are working on it in our spare time.

tjones
2021-09-05 07:12
Verifier support will be soon though - that work is mostly done.

aram
2021-09-05 07:13
cool! cheers

tjones
2021-09-05 07:13
Let me know if any further clarification will help

tausif2909
2021-09-06 05:30
What is the most stable version of `pactV3` and `pact-core` , My PR reviewer is not happy If I use `beta` version while adding depedencies

tjones
2021-09-06 05:33
They're all considered unstable.

tjones
2021-09-06 05:33
Pragmatically you could pin one that works for you, and leave it at that.

divyalakshmi.gk
2021-09-07 01:46
has joined #pact-js

constantin.jaeck
2021-09-07 02:24
has joined #pact-js

narendra_uppara
2021-09-07 07:17
has joined #pact-js

nikuplanchiwar
2021-09-07 08:03
has joined #pact-js

sdomeracki
2021-09-07 10:22
has joined #pact-js

jgfarias42
2021-09-07 11:53
has joined #pact-js

gibraltor999
2021-09-07 12:03
has joined #pact-js

jgfarias42
2021-09-07 12:23
[JEST PACT] Hi folks, I am having some trouble starting up the Mock Server using Jest Pact [1]. I set up an interactions similar to how it is explained on the repository, simply declaring it with _pactWith_ and adding an interaction to the injected _provider_ variable. (First image) When I run the test, before any call is made to the server, I get this error during the attempt to call _spawn_ on the server (this command is not executable on my terminal - should it? I didn't find on _brew_). I am also sharing my _jest.pack.js_ and the _package.json_. I have a toy/POC project on the same machine and with the same setup, and it works with this approach. I am on a Mac Intel 11.5. Any thoughts? 1 - https://github.com/pact-foundation/jest-pact

tjones
2021-09-07 13:57
Can you tell us: ? What version of `pact-js` and `pact-node` you are using please? You can find out with: ```npm ls @pact-foundation/pact npm ls @pact-foundation/pact-node``` ? What OS and architecture you are running on

tjones
2021-09-07 13:58
This error is saying that the binary isn't present, which means that your npm install might have failed. To test this, can you try deleting your `node_modules` directory and running `npm install` again please?

tjones
2021-09-07 13:59
Yes, the pact mock service should be runnable on the command line, but not at the path in that error message

tjones
2021-09-07 14:01
it is in `<your-project-home>/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63/pact/bin/pact-mock-service`

tjones
2021-09-07 14:03
note that the binaries are downloaded during install, so if you're doing `--ignore-scripts` when you install, then pact won't work

tjones
2021-09-07 14:04
I'd like to clean up the error reporting in this case, I think we can do a lot better.

tjones
2021-09-07 14:05
> I have a toy/POC project on the same machine and with the same setup, and it works with this approach. This is good news! Is it using the same versions of pact and pact-node?

tjones
2021-09-07 14:06
There definitely is either a bug or an opportunity for improvement here somewhere, and I'd really like to get a fix out if we can.

tjones
2021-09-07 14:07
If you are still experiencing this issue after removing node modules and doing npm install again, it would be awesome if you could put it up somewhere I can download it and take a look

gibraltor999
2021-09-07 14:43
There is an issue which I faced recently that if the project path has a folder with space then the tests wont run and they just give a error that '*eg: ERROR (23471 on C02FTDNXMD6M): pact-node@10.13.3: Pact Binary Error: node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63/pact/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory'.*

gibraltor999
2021-09-07 14:44
Can this be addressed with better error handling so that it doesnt become a nightmare to understand the issue.

gibraltor999
2021-09-07 14:45
2. Same goes with the provider name being case sensitive. AT the consumer side I provided the provider name as : ABc and at the provider side it was ABC, and again error was not user friendly to investigate



tjones
2021-09-07 15:19
Oh, this one is new. Hmm.

tjones
2021-09-07 15:19
It would be great if the broker warned if you were asking for a consumer that's similarly named to another

tjones
2021-09-07 15:20
(especially if it just differed in case)

tjones
2021-09-07 15:21
Thanks for the reports, though! Even though we already had these two, I'd prefer we hear about an issue twice than not at all.

tjones
2021-09-07 15:22
I'm not sure we can do much at the framework level, though - since we ask the broker for the pacts with a specific string.


tjones
2021-09-07 15:27
I hope you don't mind that I credited you. Feel free to vote for it over there.

norway.martin
2021-09-07 18:38
has joined #pact-js

matt.fellows
2021-09-07 22:16
The broker does warn you if you create similarly named contracts


tjones
2021-09-08 01:35
Ah! Maybe this is an edge case? @gibraltor999 would you be able to share the exact names you used? What version of the broker were you using?

valeriia.danylenko
2021-09-08 07:39
hello everyone) I'm relatively new to development so I apologize in advance if my question will sound silly or somethings. I am recently working on implementing contract testing on provider side (which is a NestJS microservice). Presumably my microservice structure looks this way (see the picture): There are different modules that represent different features of a microservice. All of these modules are imported to AppModule. Additionally there's a common folder that hosts CoreModule. This module, in turn, imports DatabaseModule. Database module imports MongoModule (where DB connection is established) and uses MongoService as provider. CoreModule is used in all feature modules of a microservice. While trying to write a pact test I came arcoss an issue. Generally, during unit tests ordinary database connection is replaced with mock connection provided by mongo-memory-server. This is simply achieved by creating a testing module and using provide/useFactory block for a provider that needs to be mocked. I studied nestjs-provider-pact example, and it seems that we create a test module based on the whole application, additionally we also include PactModule (which is not a testing module but a real-time one). This PactModule import a module, a provider of which I would later use to set state of a provider. So my questing is: I want to seed my mocked database with some data in stateHandler block. In order to do it I need to inject mocked db-connection to PactModule, and make sure that the same mocked-connection is used during testing module initialization. Is there a way to do it?

matt.fellows
2021-09-08 08:03
I think that might be NestJS specific question, which I can?t answer. But perhaps Omer can (he created a NestJS library. See https://github.com/omermorad/nestjs-pact) But as a general rule, in the state handlers you need access to the mocking context, and you would usually do it there. @omer.moradd @omer.morad (sorry for the double, not sure which of the handles is real Omer!)

omer.moradd
2021-09-08 08:12
Hey! @valeriia.danylenko I read your question, I will PM you and we?ll try to solve it together @matt.fellows@matt.fellows@matt.fellows after we?ll figure out the solution I will post it here so everyone can enjoy it Also, do you think maybe it?s worth creating an issue in GitHub?

adamdullenty
2021-09-08 08:23
has joined #pact-js

gibraltor999
2021-09-08 08:36
@tjones: Pact Broker version used: Pact Broker Version: 2.83.0

gibraltor999
2021-09-08 08:37
Just a simple string : *Provider* (I used this a the consumer side) and I used *provider* at the provider side

matt.fellows
2021-09-08 10:19
Oh wow, thanks for the quick response Omer!

matt.fellows
2021-09-08 10:20
Only if you think it?s an issue with the framework or an obvious inclusion for documentation or something

marcin.baranowski953
2021-09-08 10:59
Hello, From time to time, when I run contract tests on consumer side (js), I get this error msg: ```Error: Pact startup failed; tried calling service 10 times with no result.``` I've found out that this happens only when I have running docker-compose up on my machine... but not always. It depends on services I have started using docker-compose. So I've began to check which service is causing trouble. I've done binary elimination (of 8 services). It turned out that none of the services alone is causing trouble: I can run only first half and pact server is running fine and also when running the second half pact server is still ok. Only mixes of them makes pact server unable to run. Checking all of these combinations would take a lot of time (256 possibilities with only this one docker-compose file, I have more of them :wink: ), so I prefer to find source of the problem. Anyone has had such issue? Do You have any suggestions? Unfortunately I cannot send here original docker-compose.

tjones
2021-09-08 11:00
Hmmm... I can't think of anything that would cause this

tjones
2021-09-08 11:00
are you setting a specific port when you're starting pact?

tjones
2021-09-08 11:01
What version(s) of pact are you using?

marcin.baranowski953
2021-09-08 11:02
yes, I set specific port (already tried few others to make sure it doesn't clash with any other)

tjones
2021-09-08 11:02
What happens if you don't supply a port?

marcin.baranowski953
2021-09-08 11:03
The latest versions: ``` '@pact-foundation/pact': 9.16.0 '@pact-foundation/pact-node': 10.13.5```

tjones
2021-09-08 11:05
One thing that might be happening is that the timeout might need to be longer. In pact-node, I think the test timeout isn't respected by the thing that waits for the service

marcin.baranowski953
2021-09-08 11:05
The same error, when I don't supply port

tjones
2021-09-08 11:06
we fixed this in pact-core, hold on a moment and I'll backport it

tjones
2021-09-08 12:01
Apologies, that took longer than I expected, because of some reasons. If you bump your pact version, you should get: ``` '@pact-foundation/pact': 9.16.1 '@pact-foundation/pact-node': 10.13.7```

tjones
2021-09-08 12:01
This adds a `timeout` option to `new Pact()`, that you can configure to ask it to wait longer. This is probably appropriate in docker, where everything takes much longer.

tjones
2021-09-08 12:01
the default is `30000` milliseconds

tjones
2021-09-08 12:06
@jgfarias42: Try `"@pact-foundation/pact": "^9.16.1"` - this will bump pact-node to 10.13.7, which contains a fix for at least one issue that caused this.

tjones
2021-09-08 12:06
@marcin.baranowski953: Let me know if that fixes it. I'm off to bed here, but if you have any further problems, I can take a look tomorrow.

marcin.baranowski953
2021-09-08 12:08
Okey, I will check it later and let You know :wink:

tjones
2021-09-08 12:12
:taco: for @omer.moradd for a super quick response!

martin.a.harkins
2021-09-08 12:15
has joined #pact-js

martin.a.harkins
2021-09-08 12:40
Howdy ! I'm trying to set up the verification tests for a provider (ie. `MyProviderService`) that provides both a REST API (using `Verifier`) and Kafka Messages (using `MessageProviderPact`). I'm having some trouble with that... Is that at all possible while keeping a common provider name ? ? I've already grouped all the REST consumers into a Verifier, and all the Event consumers into a MessageProviderPact ? Individually, each contract passes (ie. by having separate Verifiers for each Provider <-> Consumer REST communications, and specifying a specific pactUrl to that consumer) > As a side note, we actually have multiple consumers for the REST APIs and multiple consumers for the Event messaging...

martin.a.harkins
2021-09-08 12:41
Please let me know if you require more information. My guess that this might not be possible and that I should declare multiple provider names...

martin.a.harkins
2021-09-08 12:43
That's with Pact 2

tjones
2021-09-08 13:02
Unfortunately, both pact spec version 2 and (I think) 3 require different consumer names for the different types of pact

tjones
2021-09-08 13:03
Usually I?d do something like ?FooConsumer http? and ?FooConsumer kafka?

tjones
2021-09-08 13:03
Ah, sorry- the question is about providers. I believe the same is true for provider names

martin.a.harkins
2021-09-08 13:15
okay thanks. Found a fun thing playing around with consumerVersionSelectors: Given consumers: ? MyWebApp ? MyKafkaConsumer ```consumerVersionSelectors: [{ tag: 'develop', consumer: 'MyKafkaConsumer', }],``` Does only test that consumer, but tests of course ALL versions. ```consumerVersionSelectors: [{ tag: 'develop', latest: true, consumer: 'MyKafkaConsumer', }],``` Tests only the latest version, but tests ALL the consumers. NOOO so CLOSE !

omer.moradd
2021-09-08 13:26
Yayyy

omer.moradd
2021-09-08 13:26
Thanks :))

martin.a.harkins
2021-09-08 13:35
Ah I had the prop consumerVersionTag specified. Specifying the consumerVersionSelectors + lastest:true + consumer: 'XXX' now works !

jgfarias42
2021-09-08 14:00
Hi Timothy, sorry the delay. Yes, the issue is exactly the absence of the mock server binaries. On the POC project, I can see them (first image), but on my "real" project, they are not being downloaded (second image). Unfortunately, I cannot share the code, because it's proprietary. The POC is using Pact 9.12/Pact-Node 10.13.5 (third image). It works fine. I've upgrade the real project to Pact 9.16/Pact-Node 10.13.7 (fourth image), but it doesn't work. I've copied manually these binaries to the real project and everything works fine :rolling_on_the_floor_laughing: Note: I have to use Yarn because the project uses Yarn's workspaces, NPM doesn't support it.

valeriia.danylenko
2021-09-08 14:01
@omer.moradd Thank you so much for such thorough assistance. @matt.fellows at the end of the day it was Nestjs specific issue (and my lack of understanding nestjs testing flow). And the provided example and Pact itself work perfectly well.

marcin.baranowski953
2021-09-08 14:19
When I provided `timeout: 31000` or higher value I get: ```Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.```

marcin.baranowski953
2021-09-08 14:25
I guess one think may be not clear: I don't need to run contract tests along with running docker-compose. Me and my teammates use docker-compose on daily basis and running contract tests on local machines would be just inconvinient. Right now (until we find cause) it requires stopping docker-compose and rerun it after running contract tests.

matt.fellows
2021-09-08 14:49
Another :taco: for @omer.moradd

matt.fellows
2021-09-08 14:49
Thank you!

omer.moradd
2021-09-08 14:50
You welcome :hearts:

tjones
2021-09-08 23:44
Ah, is this yarn2? Yarn made a bunch of breaking changes to the way the npm ecosystem works (like ignoring the scripts in some cases)

tjones
2021-09-08 23:46
I wonder if this is a problem that happens because of yarn workspaces...

tjones
2021-09-08 23:47
yarn also ignores any error output from packages during install, which makes it hard to debug what's going on (maybe you can configure yarn not to do that, I don't know)

tjones
2021-09-08 23:50
> Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. This is from your testing framework, not pact.

tjones
2021-09-08 23:51
You'll have to increase both timeouts

rocco.smit
2021-09-09 06:20
has joined #pact-js

jgfarias42
2021-09-09 08:40
Still Yarn 1: Version 1.22.11 I will check the script ignoring - I am new to JS/NPM/Yarn, so it's basically try and error on my side :smile:

andrei_mironau
2021-09-09 10:00
has joined #pact-js

febin.sathar
2021-09-09 10:16
has joined #pact-js

jcaromiq
2021-09-09 11:47
has joined #pact-js

marcin.baranowski953
2021-09-09 12:22
Thanks @tjones I've increased mocha timeout and now it works like a charm :slightly_smiling_face:

tjones
2021-09-09 13:06
Awesome! We have a wrapper for jest that sets up sensible defaults for timeouts etc. Once the pact-js v10 is out, I?m planning to take a look at a similar interface for mocha. Should be a fairly straightforward port I reckon.

jgfarias42
2021-09-09 14:21
Anyway to runt he script manually? If so, I think I can make a workaround. (I will still check if this issues happens on my Jenkins setup)

mirko.zipris
2021-09-09 20:08
has joined #pact-js

tjones
2021-09-10 01:26
No, but you can download the binaries separately

tjones
2021-09-10 01:28
I think 9.16.1 will solve this problem

tjones
2021-09-10 01:30
To summarise: 1. I think you might be hit by a bug that is fixed in 9.16.1. The bug caused pact to not find the binaries (even though they were there) in some cases 2. If the problem is that yarn is not downloading the binaries, then you can download them manually yourself and put them in `<your-project-home>/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63` (but the location changes on different platforms, so you may have frustrations in CI). If that's what's happening, it's a yarn bug - it's supposed to run a `postinstall` script

tjones
2021-09-10 01:33
I looked it up - yarn 1 should still respect the scripts. So, unless you're running `yarn install --ignore-scripts`, I think you're hitting the bug fixed in 9.16.1.

mui_ume
2021-09-10 03:02
i have a body payload that want to match single value instead of range like 2-5 so can I use regular expression using the like from pact to match? ```size: like(/[0-9]+\.[0-9]?/),```

mui_ume
2021-09-10 03:42
it does not work so I use a value here is my github repo https://github.com/LayMui/pactjs-demo/blob/master/__tests__/address.spec.js line 22 unit: 0.1. basically the dev team has change from range 2-5 to a single value. so I like to use pactjs to catch such changes.

dotelnp
2021-09-10 06:48
has joined #pact-js

jgfarias42
2021-09-10 08:01
I guess it's not the same bug, since I am using version 9.16.1 already. I will let you know how it goes on CI.

tjones
2021-09-10 08:12
What do you mean by it does not work?

tjones
2021-09-10 08:12
You can't use `like` in that way


tjones
2021-09-10 08:14
you want to use: ```size: Matchers.term({ generate: '1.2', matcher: '[0-9]+\.[0-9]?' })```

tjones
2021-09-10 08:14
Although, I 'm not sure what you want to achieve with that regular expression

tjones
2021-09-10 08:14
I think it says at least one digit, then a period, and then optionally a digit?

tjones
2021-09-10 08:15
So, ```1123.5 // matches 1. // matches 1.0 // matches 1.124 // does not match```

mui_ume
2021-09-10 08:15
yes. it should not be a range such as 2-5

tjones
2021-09-10 08:15
If you want to match a number ,just use `Matchers.decimal()`

mui_ume
2021-09-10 08:15
2-5, 1-3, does not match becos it?s a range

tjones
2021-09-10 08:16
Pact doesn't support ranges for numbers

tjones
2021-09-10 08:16
Although we probably should

tjones
2021-09-10 08:16
if you say `Matchers.like("1-3")` you are saying "match a string, for example `"1-3"`"

tjones
2021-09-10 08:17
`like` is a convenience matcher that matches on type only.

tjones
2021-09-10 08:38
Ah, apologies! I must have misread

tjones
2021-09-10 08:40
can you tell me what ```ls node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63``` prints?

tjones
2021-09-10 08:40
and if nothing, what do you get with: ```ls node_modules/@pact-foundation/pact-node/standalone```

tjones
2021-09-10 08:42
what happens if (in your project directory), you type: ``` npx pact-broker version``` and ```npx pact-mock-service``` (you'll need to control-c to get out of that last one, if it is successful)

mui_ume
2021-09-10 08:52
Matchers.decimal() does not work, I got this error TypeError: Cannot read property ?decimal? of undefined

tjones
2021-09-10 08:53
You have to import the matchers. Please see the example in the documentation I linked.

tjones
2021-09-10 08:54
^ Once the native libraries have finished cooking for that release, we'll have promises working properly for V3 state handlers. :raised_hands: :raised_hands: :raised_hands:

mui_ume
2021-09-10 08:54
can I use ```size: like(1.0)```

tjones
2021-09-10 08:54
If you are only wanting to match any number, then yes.

tjones
2021-09-10 08:55
I'm pretty excited about that release.

mui_ume
2021-09-10 08:55
does this match the below? ```1123.5 // matches 1. // matches 1.0 // matches 1.124 // matches```

mui_ume
2021-09-10 08:56
size: 1.0 will only match 1.0 whereeas size: like(1.0) will match any number as well as decimal number, right?


mui_ume
2021-09-10 08:56
got it thanks

matt.fellows
2021-09-10 08:59
Also note, because JS, 1.0 gets converted to 1 and becomes an integer match.

matt.fellows
2021-09-10 08:59
You need to use something like 1.1 in your example otherwise when the provide side runs it will fail

matt.fellows
2021-09-10 09:01
Many a :taco: for you @tjones! I've not kept up with your PRs recently as they're coming in so thick and fast. Looking forward to reviewing my emails when I'm back next week :rolling_on_the_floor_laughing:

tjones
2021-09-10 09:06
Oh, also, this release quietly introduces support for node 16 for the beta branch

sameer.patil
2021-09-10 18:42
has joined #pact-js

b.1.alpha
2021-09-10 19:17
has joined #pact-js

vicenzo
2021-09-10 22:50
Hello!! I think i need some help, trying to get a poc done and my pact file is not being written even though the console logs say they are. (I am on my phone rn, so i can't get to the code snippet). Got my provider.finalize() on the after block, and provider.verify() on afterTest()

matt.fellows
2021-09-11 02:38
When you're back at your desk it's be great to see code and/or logs. If logs say it's written it should be, perhaps it's not where you'd expect?

matt.fellows
2021-09-11 02:38
Also just check that you're correctly handling the functions, both of which are promises

naushad_amin
2021-09-11 23:15
has joined #pact-js

mui_ume
2021-09-13 07:47
how about if the value can be null or undefined? can I use like([1.1, null, undefined])

tjones
2021-09-13 07:53
No. Remember that `like` *only* matches on the type of the example you give it. So if you do this: `like([1.1, null, undefined])`, you are saying "match an array with three items, the first one is a number, the second is null, and the third is undefined. Also, you are setting up a JSON expectation here, and `undefined` doesn't exist in JSON. So, it's more like saying `[number, null, null]`. Lastly, pact works on specific examples, not a schema for appropriate responses. So, if you want to test that the server might produce `null` in some cases, you'll want a separate test for it

jgfarias42
2021-09-13 12:31
The content of pact-node/standalone is only a _pact_ folder. Here is the content of this folder:

jgfarias42
2021-09-13 12:32
The standalone folder has some checksums and installation scripts: (In the real project, we have the same, except the darwin-1.88.63/pact folder.

jgfarias42
2021-09-13 12:40
NPX for the _toy project_ (that is working):

jgfarias42
2021-09-13 12:43
And we get empty results on the _real project, b_ecause the darwin-1.88.63 folder is not there

jose_rodriguez
2021-09-13 13:16
has joined #pact-js

kyle_evans
2021-09-13 13:16
has joined #pact-js

thanuxxxx
2021-09-13 15:31
Am I using `eachKeyLike` correct way? I am getting mismatch error for the following scenario. Can anyone help me out? Here is an example how to use `eachKeyLike` from `pact-js` https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/e2e/test/consumer.spec.js This is a modal response ```const SampleResponse = { categories: { additionalProp1: { id: 'string', items: ['string'], name: 'string', sortOrder: 0, }, additionalProp2: { id: 'string', items: ['string'], name: 'string', sortOrder: 0, }, // Nth additional Prop additionalPropN: { id: 'string', items: ['string'], name: 'string', sortOrder: 0, }, }, };``` So I created a matcher something like this ```const expectation = { categories: eachKeyLike('1SMKX6JGWKY3J', { id: regex(/^[A-Z0-9]+$/,'1SMKX6JGWKY3J'), name: string('Dessert'), sortOrder: integer(3), items: atLeastOneLike(string('F79QJX241ZAHP')), }) }``` Here is the actual response from provider ```const actualResponse = { categories: { '4KS8YA1PY4YPC': { id: '4KS8YA1PY4YPC', name: 'Plain ol\' Crepe', sortOrder: 1, items: ['19AGCTC43X5YC'], }, 'D70N53J6R34K9': { id: '41SJNCEK3FXTJ', name: 'Flavored Crepes', sortOrder: 0, items: ['D70N53J6R34K9'], }, }, }``` This is the mismatch body log ```/* 1.1) body: $.categories Expected 1SMKX6JGWKY3J={"id":"1SMKX6JGWKY3J","items":["F79QJX241ZAHP"],"name":"Dessert","sortOrder":3} but was missing { + "4KS8YA1PY4YPC": { + "id": "4KS8YA1PY4YPC", - "1SMKX6JGWKY3J": { - "id": "1SMKX6JGWKY3J", + "name": "Plain ol' Crepe", - "name": "Dessert", + "sortOrder": 1, - "sortOrder": 3 "items": [ + "19AGCTC43X5YC" + ] - "F79QJX241ZAHP" - ], + }, + "D70N53J6R34K9": { + "id": "D70N53J6R34K9", + "name": "Flavored Crepes", + "sortOrder": 0, + "items": [ + "19AGCTC43X5YC" + ] } */``` It works fine when I feed the actual key into the matcher something like this ```const expectation = { categories: eachKeyLike('4KS8YA1PY4YPC', { id: regex(/^[A-Z0-9]+$/,'4KS8YA1PY4YPC'), name: string('Dessert'), sortOrder: integer(3), items: atLeastOneLike(string('F79QJX241ZAHP')), }) }``` I suspect I am using `eachKeyLike` method in a wrong way? Any ideas?

rahul.louis
2021-09-13 15:55
has joined #pact-js

a.koka
2021-09-13 17:01
has joined #pact-js

efloresambrosio
2021-09-13 20:09
has joined #pact-js

matt.fellows
2021-09-13 22:43
hmmm it looks correct to me

matt.fellows
2021-09-13 22:43
what does your provider verifier look like?

thanuxxxx
2021-09-13 22:48
What do you mean by that? I have this for provider side ``` @TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); }```

matt.fellows
2021-09-13 22:51
which version of Pact JVM are you using?

matt.fellows
2021-09-13 22:51
can you please also share the relevant pact file (or interactions within the pact file?)

thanuxxxx
2021-09-13 22:52
Version `4.1.16`

thanuxxxx
2021-09-13 22:58
```{ body: { categories: { '1SMKX6JGWKY3J': { id: '1SMKX6JGWKY3J', items: ['F79QJX241ZAHP'], name: 'Dessert', sortOrder: 3, }, }, }, matchingRules: { body: { '$.categories': { combine: 'AND', matchers: [ { match: 'values', }, ], }, '$.categories.*.id': { combine: 'AND', matchers: [ { match: 'regex', regex: '^[A-Z0-9]+$', }, ], }, '$.categories.*.items': { combine: 'AND', matchers: [ { match: 'type', min: 1, }, ], }, '$.categories..items[]': { combine: 'AND', matchers: [ { match: 'type', }, ], }, '$.categories.*.name': { combine: 'AND', matchers: [ { match: 'type', }, ], }, '$.categories.*.sortOrder': { combine: 'AND', matchers: [ { match: 'integer', }, ], }, }, }, };```

tjones
2021-09-13 23:36
Yes, this supports the theory that it wasn't downloaded correctly when install was run

tjones
2021-09-13 23:36
did you try removing `node_modules` and running install again, and what logs were printed when you did that?

matt.fellows
2021-09-14 00:23
it looks correct to me

matt.fellows
2021-09-14 00:23
@uglyog any ideas?

uglyog
2021-09-14 00:26
The values matcher is not being applied properly. I think it is an issue with Pact-JVM.

uglyog
2021-09-14 00:27
Can you raise an issue with Pact-JVM?

matt.fellows
2021-09-14 00:41
Thanks for checking Ron

thanuxxxx
2021-09-14 00:44
Okay done

matt.fellows
2021-09-14 00:48
Might be worth tinkering with the JVM version to see if a previous one works

thanuxxxx
2021-09-14 00:50
Sure will give a try. Thank you guys

mui_ume
2021-09-14 01:24
ok so if the value is null, it will still match like(1.1)?

matt.fellows
2021-09-14 01:50
no, `null` is not a number


mui_ume
2021-09-14 02:27
ok so I can just leave that data field to accept anything then? becos I still want to have pact test for shift left strategy for the microservices API

matt.fellows
2021-09-14 02:34
If your consumer test doesn?t use that field, it?s irrelevant what you put in that field. You *should not* include it if you don?t need it in your test

matt.fellows
2021-09-14 02:34
if you need it to be `null` , you should write a test that expects that. If you need it to be a float, you should write a separate test for that scenario

olle_hallin
2021-09-14 05:50
has joined #pact-js

divyalakshmi.gk
2021-09-14 06:00
Hello everyone, I am facing an issue with verification Pact broker status . Its showing Unverified. The test cases are passing in consumer and provider end. need your help to have a look on that, if anything I  am missing in the code or publishing part. The Provider is written in NodeJS, Typescript and pact test cases using jest- jasmine. In the attachment below: The first one client-testing - provider-testing, I have created for a pact test for another API. It is showing Unverified. The pact tests are passing locally. The second one otp-client- digix , was already published. Here I am adding pact testing to one more API and trying to publish it separately and its failing Can you please guide me to debug this issue. am sharing the screenshot of the PACT Flow

tjones
2021-09-14 06:15
Are you publishing your verification status from the verifier?

tjones
2021-09-14 06:15
What version of pact-js are you using?

tjones
2021-09-14 06:15
Can you share your configuration for the `Verifier` call?


matt.fellows
2021-09-14 07:04
You would usually only publish verification results from your CI servers

matt.fellows
2021-09-14 07:05
you can either explicitly set it to publish (as per the above docs)

matt.fellows
2021-09-14 07:05
or set this env var `PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true`

matt.fellows
2021-09-14 07:05
For clarity, we _don?t_ recommend doing this from your dev machine, because you may do that whilst still developing the feature, and invalidate any `can-i-deploy` results

matt.fellows
2021-09-14 07:05
I?d highly recommend doing this workshop: https://docs.pactflow.io/docs/workshops/ci-cd/

a.babenko
2021-09-14 14:00
has joined #pact-js

vasavi.balanagu
2021-09-14 16:49
has joined #pact-js

samuel.sjoberg
2021-09-14 21:49
has joined #pact-js

domingo
2021-09-14 23:51
has joined #pact-js

pradeepkumarstudent20
2021-09-15 03:32
has joined #pact-js

jgfarias42
2021-09-15 11:35
Hi Timothy. I am not so expert on node, but it seems my project has different modules (two package.json). Someone had already defined the pact-js and jest-pact dependencies on another package.json and when I did the "master" yarn install, it mess up. I removed the duplication and it seems to be ok now. Thank you for all the investigation and guidance.

sushant.soni
2021-09-15 12:18
Hello everyone, I am trying to support multiple provider states in an interaction on the provider side. But I couldn?t find any example for the same. Can someone please point me to a resource I can refer to?

matt.fellows
2021-09-15 12:19
are you using the new v3 package, or the current stable?

matt.fellows
2021-09-15 12:20
on the provider side, supporting multiple states is simple - you create state handlers for each state you need to support, and pact will call 0 or more of them

sushant.soni
2021-09-15 12:23
v3

sushant.soni
2021-09-15 12:25
Is my understanding incorrect when I say that the consumer wants 2 states which are interdependent. For example 1. User is logged in 2. User has a product in the wishlist 2nd is possible only after 1.

matt.fellows
2021-09-15 12:30
those states look like good states to me

matt.fellows
2021-09-15 12:31
I may be incorrect about this, but there is no ordering as far as I?m aware of

matt.fellows
2021-09-15 12:35
You could also create a state ?User is logged in and has a product in the wishlist?

matt.fellows
2021-09-15 12:35
If you want to be able to re-use states on the provider, then one must be unaware of the other

matt.fellows
2021-09-15 12:36
If they are coupled, then I?d just create a single state for that scenario

sushant.soni
2021-09-15 12:36
Perfect, that clears a lot.

sushant.soni
2021-09-15 12:36
This might be a #general question, but what do you recommend while setting up provider states, return a mock response data or from a real service?

matt.fellows
2021-09-15 12:45
mock data


tjones
2021-09-15 13:53
It depends what you mean by "real service". I usually mock at the boundary to any repository layers internally in the provider

tjones
2021-09-15 13:54
This means that the provider's business logic is executed during the test. It's best practice not to try to exercise the business logic with the pact test, but I think it's good if the tests have some coverage of the business logic (if that makes sense)

tjones
2021-09-15 13:57
You're welcome! Glad it's sorted!

bryan
2021-09-15 15:16
has joined #pact-js

bryan
2021-09-15 15:20
I?m contracting for a company that has a strict policy about which software can run on our computers. We can get the standalone binaries approved and put into the company?s ?software center? so it?s already installed on our systems, but I?ve looked through the docs and some of the source code and can?t seem to find a way to point pact to these approved binaries. Am I missing something?

paulorochag
2021-09-15 15:44
Guys, my contract test is breaking and I believe it is because of the query params, can you provide me with support? I'm not really sure what's going on, but it's returning exactly what he expected.

paulorochag
2021-09-15 18:29
Again with other route :confused:

dboxler
2021-09-15 18:35
has joined #pact-js

paulorochag
2021-09-15 19:00
I believe I discovered the problem. In the consumer, I'm implementing: ```query: { autoDispatch: 'false', },``` But in the _pact.log_ the interaction is getting like ``` "query": { "autoDispatch": [ "false" ] },```

paulorochag
2021-09-15 19:01
@tjones, @matt.fellows

paulorochag
2021-09-15 21:06
in fact what I showed in the screenshot above is not a error, I saw that it is right. I've analyzed it again and it looks like the test request ('http://cipagarmeApi.post') is running before the interaction is registered ('addInteraction'). I will try to understand why in some tests, intermittently, the request is made before the interaction. If you have some light while I investigate it would be a great help.

tjones
2021-09-15 21:55
Thanks- the problem is that you have to wait for the provider to add the interaction before you can start your test. You can do this by returning the result from addInteraction in your before call

matt.fellows
2021-09-15 22:43
You can do it


matt.fellows
2021-09-15 22:43
Apologies, those docs were removed in the latest version because we?re going to bundle it into the package

matt.fellows
2021-09-15 22:44
but that should temporarily get you going, whilst we get that into all of the Pact JS releases

tjones
2021-09-15 22:48
Or using async/await as you do in your test

keerthisiv
2021-09-16 03:59
has joined #pact-js

adelina.simion
2021-09-16 08:41
has joined #pact-js

sushant.soni
2021-09-16 08:52
my provider calls another microservice to fetch some data. So should we always use the actual data from this microservice or should we stub it?

tjones
2021-09-16 08:58
I usually stub within your provider

tjones
2021-09-16 08:58
eg, your provider's code looks something like this: ```controller -> service -> otherMicroserviceClient``` then it makes a network call to the other microservice

tjones
2021-09-16 08:59
instead of mocking the network call, I would mock the client interface internally in your provider

tjones
2021-09-16 09:00
that way you can express your mock as: ```getUser("STEVE") will return someMockUser``` instead of all the gory details of however that request works

akke.luukkonen
2021-09-16 10:29
has joined #pact-js

alejandro.pena
2021-09-16 13:37
has joined #pact-js

bryan
2021-09-16 14:03
How do I tell pact to use a binary installed on my system instead of the downloaded one?


bbleach
2021-09-17 07:30
has joined #pact-js

sushant.soni
2021-09-17 13:35
Hi Whenever my provider encounters multiple provider states in the pact, it is not able to set those up. This is what I get from the DEBUG logs ```pact-node@10.13.7: DEBUG: Setting up provider state '' for consumer 'xyz' using provider state set up URL http://localhost:56438/_pactSetup``` and ```pact@9.16.1: No state handler found for "null", ignoring```

sushant.soni
2021-09-17 13:39
CC: @tjones

matt.fellows
2021-09-17 13:42
You need to use the v3 beta, please see the readme. The current stable package is not v3 compatible (which is the spec where multiple states were supported)

sushant.soni
2021-09-17 13:57
Thanks :slightly_smiling_face: trying that now

sushant.soni
2021-09-17 15:08
Thanks Matt, works like a charm!

paulorochag
2021-09-17 15:19
Timothy, that async/await suggestion was what we implemented and it worked.

tjones
2021-09-17 15:54
Glad to hear you got it working! Let us know if you have further questions

divyalakshmi.gk
2021-09-20 04:33
@tjones Verifier config details is as below: const opts = { logLevel: 'info', providerBaseUrl: 'http://localhost:8080', provider: 'provider-testing', providerVersion: '1.0.0', pactBrokerUrl, pactBrokerToken, stateHandlers: { 'Returns the Id details of 5cbd5f90':IdDetails, }, if (http://process.env.CI || process.env.PACT_PUBLISH_RESULTS) { Object.assign(opts, { publishVerificationResult: true, }); } return new Verifier(opts).verifyProvider().finally(() => { api.stop(); });

matt.fellows
2021-09-20 04:51
What does the terminal output look like when you run it?

divyalakshmi.gk
2021-09-20 05:04
Provider output:

divyalakshmi.gk
2021-09-20 05:04
consumer output:

divyalakshmi.gk
2021-09-20 05:14
Publishing results:

divyalakshmi.gk
2021-09-20 05:16
pact broker after publishing:

matt.fellows
2021-09-20 06:10
I don?t understand

matt.fellows
2021-09-20 06:10
it seems like your provider test is publishing a Pact, that?s confusing

matt.fellows
2021-09-20 06:10
the provider verifies a pact that a _consumer_ publishes

matt.fellows
2021-09-20 06:11
That terminal output is definitely not the output i?d expect to see if running the verifier code you shared above

rushideshpandes
2021-09-20 13:11
has joined #pact-js

gemhar
2021-09-20 14:33
has joined #pact-js

bryan
2021-09-20 14:37
@matt.fellows this tells me where to put the zip/tarball so the install script can unzip it itself? in this case, I have to have Software Center install the pact binaries so it sets the special security flag so it has permission to run? the zip/tarball is already unzipped/untarred and I need to tell pact where to run the executable from

vicenzo
2021-09-20 21:25
finally remembered tocome back

vicenzo
2021-09-20 21:26
```2021-09-20T21:19:41.585Z INFO @wdio/local-runner: Shutting down spawned worker [2021-09-20 21:19:41.589 +0000] INFO (24191 on Vicenzos-MBP): pact@9.16.1: Pact File Written [2021-09-20 21:19:41.589 +0000] INFO (24191 on Vicenzos-MBP): pact-node@10.13.7: Removing Pact process with PID: 24205 [2021-09-20 21:19:41.591 +0000] DEBUG (24191 on Vicenzos-MBP): pact-node@10.13.7: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2021-09-20 21:19:41.593 +0000] INFO (24191 on Vicenzos-MBP): pact-node@10.13.7: Deleting Pact Server with options: {"consumer":"WebApp","cors":true,"dir":"/Users/vicenzo/Code/app/tests/pacts","host":"127.0.0.1","log":"/Users/vicenzo/Code/app/logs/pact.log","pactFileWriteMode":"overwrite","port":58919,"provider":"Backend","spec":2,"ssl":false,"timeout":30000} 2021-09-20T21:19:41.839Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully 2021-09-20T21:19:41.840Z INFO @wdio/local-runner: shutting down```

vicenzo
2021-09-20 21:27
```export const pactServer = new Pact({ consumer: "WebApp", provider: "Backend", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "tests", "pacts"), logLevel: "debug", cors: true }); export const publisher = new Publisher({ publishVerificationResult: true, pactBroker: 'http://localhost:9292', consumerVersion: version, pactFilesOrDirs: [path.resolve(process.cwd(), "tests", "pacts")], }); const server = exec('gulp start-pact-dev'); exports.config = merge(wdioConf.config, { baseUrl: 'http://localhost:8083', specs: [ './tests/webdriverio/specs/**/*.pact.js' ], exclude: [ './tests/webdriverio/specs/**/*.e2e.js' ], onPrepare: async function (config, capabilities) { server.stdout.pipe(process.stdout); pactServer.setup().then(() => pactServer.addInteraction(LoginInteraction)); }, afterTest: function () { pactServer.verify(); }, after: function () { pactServer.finalize(); }, onComplete: function () { server.on('exit', function() { process.exit(); }); pactServer.finalize(); } });```

jsegall
2021-09-20 21:37
has joined #pact-js

vicenzo
2021-09-20 22:26
sorry to ping you @matt.fellows

matt.fellows
2021-09-21 11:28
Verify and finalize are both promises, that may be the cause as they don't appear to be handled

dalkire
2021-09-21 13:30
has joined #pact-js

mathias.duesterhoeft
2021-09-21 14:51
Hi there :wave: in version `10.0.0-beta.44` I could still pass in `pactBrokerUrl` as `undefined` and pass in `pactUrls` to use local contract files instead of a remote broker. in `10.0.0-beta.48` the tests fail with `Failed to load pact - Could not load pacts from the pact broker 'undefined' - UrlError("relative URL without a base")` If I do not pass in `pactBrokerUrl` at all (instead of `undefined`) I even get a crash of the native binary. ```[2021-09-21T14:46:41Z ERROR pact_ffi::verifier::verifier] error verifying Pact: "error: The following required arguments were not provided:\n --broker-url <broker-url>...\n --dir <dir>...\n --url <url>...\n\nUSAGE:\n pact_verifier_cli --broker-url <broker-url>... --consumer-version-selectors <consumer-version-selectors>... --dir <dir>... --file <file>... --hostname <hostname> --loglevel <loglevel> --password <password> --port <port> --provider-name <provider-name> --provider-version <provider-version> --request-timeout <request-timeout> --scheme <scheme> --state-change-url <state-change-url> --url <url>... --user <user>\n\nFor more information try --help" Error { message: "error: The following required arguments were not provided:\n --broker-url <broker-url>...\n --dir <dir>...\n --url <url>...\n\nUSAGE:\n pact_verifier_cli --broker-url <broker-url>... --consumer-version-selectors <consumer-version-selectors>... --dir <dir>... --file <file>... --hostname <hostname> --loglevel <loglevel> --password <password> --port <port> --provider-name <provider-name> --provider-version <provider-version> --request-timeout <request-timeout> --scheme <scheme> --state-change-url <state-change-url> --url <url>... --user <user>\n\nFor more information try --help", kind: MissingRequiredArgument, info: None } [2021-09-21 14:46:41.651 +0000] INFO (82237 on HAMACL00334): pact@10.0.0-beta.48: Verifying provider [2021-09-21 14:46:41.657 +0000] INFO (82237 on HAMACL00334): pact@10.0.0-beta.48: debug request/response logging enabled [2021-09-21 14:46:41.661 +0000] INFO (82237 on HAMACL00334): pact-core@13.1.6: Verifying Pacts. [2021-09-21 14:46:41.662 +0000] INFO (82237 on HAMACL00334): pact-core@13.1.6: Verifying Pact Files [2021-09-21 14:46:41.725 +0000] DEBUG (82237 on HAMACL00334): pact-core@13.1.6: sending arguments to FFI: [2021-09-21 14:46:41.726 +0000] DEBUG (82237 on HAMACL00334): pact-core@13.1.6: --request-timeout 30000 --loglevel debug --state-change-url http://localhost:57400/_pactSetup --provider-name vehicle-mission-sync --port 57400 --hostname localhost --consumer-version-selectors {"latest":true,"consumer":"some"} --user undefined --password undefined --provider-version 1 --file /path/to/contract.json [2021-09-21 14:46:41.750 +0000] DEBUG (82237 on HAMACL00334): pact-core@13.1.6: response from verifier: null, 4 [2021-09-21 14:46:41.750 +0000] ERROR (82237 on HAMACL00334): pact-core@13.1.6: !!!!!!!!! PACT CRASHED !!!!!!!!! The underlying pact core was invoked incorrectly. This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it. There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output. SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world. We're sorry about this!``` Is this a bug? Or am I missing something.

vicenzo
2021-09-21 16:04
with async/await?

hakan.celebi
2021-09-21 19:43
has joined #pact-js

matt.fellows
2021-09-22 00:54
Yes, that?s one way and assuming that code supports it. Looking at it, it looks to be in a callback, so you would need to consult the docs of the tool you?re usinsg to ensure you handle it correctly

matt.fellows
2021-09-22 00:54
Sometimes you can simply return the promise

matt.fellows
2021-09-22 00:57
It?s a bug somewhere :stuck_out_tongue:

matt.fellows
2021-09-22 00:57
The issue is (tested by running the Verifier CLI, which is essentially what Pact JS calls) the consumer version selectors are there - they require a broker configuration

matt.fellows
2021-09-22 00:58
The error message for the verification options aren?t ideal, and something we will definitely need to fix (and are, slowly)

univ.anirudh
2021-09-22 05:56
Is it idiomatic to use 'hard-coded' ID values and exact strings for defining provider states in both the consumer and provider test code? For example, if I'm testing with a required provider state - `there exists a resource with id <x>` , the exact same thing will need to be written on the provider verification test, including the same value for `<x>` (unless I have a wrong understanding of the docs). Would I need to make sure that the values here are exactly the same across both the participants? Or is there some leniency w.r.t letter casing etc?

mathias.duesterhoeft
2021-09-22 06:27
Oh - thanks a lot - I will give this a try.

abubics
2021-09-22 06:49
there are a few approaches, that's definitely one of them.

abubics
2021-09-22 06:51
Whatever approach you choose, somewhere along the line you have to coordinate on state - whether you use ? explicit values in state names, or ? implicit value only hinted at by state names, or ? in later versions of the state(s) spec, actual meta(data).

abubics
2021-09-22 06:52
you can also eschew all variant values, flexibly matching them away, and only assert on specific invariant values (e.g. IDs passed in match IDs coming back out)

univ.anirudh
2021-09-22 06:53
Do later versions of the spec allow us to pass values from the consumer for state that the provider can pick up? So the consumer could pass in, say, the resource ID while defining the state, and the provider would not need to be aware of that and could take it as a dynamic input while the verification process is going on?

abubics
2021-09-22 06:55
yeahh, something like that . . . I haven't used it yet, but I've read people talking about it in Slack

abubics
2021-09-22 06:55
I think it's in v3 or v4

univ.anirudh
2021-09-22 06:56
Ahh. That's a bit away, at least for JS. Just trying to set up a process that would be the easiest to maintain for our team. Thanks, this helped!

matt.fellows
2021-09-22 07:04
`valueFromProviderState` is the method that I think it?s called in the latest JS code (beta) and in some languages (e.g. JVM, Go)

matt.fellows
2021-09-22 07:05
It really solves the problem where you can?t control identifiers on the provider side and provider states. Hopefully in most cases, you have granular control over your provider code duration verification, and can use mocking and other common testing tools to set up data or system states as needed.

tjones
2021-09-22 07:10
Why are you passing in options but setting them to `undefined`? What are you expecting to happen?

tjones
2021-09-22 07:10
In that example, it looks like pactBrokerUser and pactBrokerPassword are probably set, but undefined.

tjones
2021-09-22 07:11
Can you share the config that you're using?

tjones
2021-09-22 07:12
I suppose that we can make pact-js handle this case, but I think the bug is in the config if you're setting options explicitly to undefined, as this is not valid (if the documentation suggests it is, then we should update it)

tjones
2021-09-22 07:13
It's a trivial change to make it ignore settings explicitly set to undefined, but I think it's probably better to throw an error, as I think it's more likely an error than intentional

mathias.duesterhoeft
2021-09-22 07:14
We run our verification tests in CI against a real broker. But on a local developer machine we do not want this - instead we use local version of the contract. So I have some common code that e.g. sets the `pactBrokerUrl` from an env variable - or `undefined` if the env variable is not there. But I can easily change this - but also - Also without this the tests failed - complaining that the `pactBrokerUrl` was not set.

mathias.duesterhoeft
2021-09-22 07:15
The hint from @matt.fellows helped though - I only set `consumerVersionSelectors` when connecting with a broker

mathias.duesterhoeft
2021-09-22 07:16
So thanks a lot for your support!

mathias.duesterhoeft
2021-09-22 07:17
Moving from version `https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.454` to `https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.458` my tests start failing because now also the metadata in the contract is verified. Can I switch this off somehow.

matt.fellows
2021-09-22 07:18
no you can?t

tjones
2021-09-22 07:18
You're welcome! I'd like to improve this case, especially if it used to (silently) work before. What do you think? Do you think we should accept `pactBrokerUrl: undefined` and potentially mask config errors, or do you think we should throw an error suggesting to not set it at all?

matt.fellows
2021-09-22 07:18
If the metadata is important, you should validate it. If not, you should remove it from the pact test

mathias.duesterhoeft
2021-09-22 07:19
I can only say that it is convenient - and TypeScript did not complain - so your types seem to allow to pass undefined. In that case I think the code should not make a difference between `undefined` and not passed.

matt.fellows
2021-09-22 07:20
It doesn?t help that the verifier feedback is really unreadable/incomprehensible

matt.fellows
2021-09-22 07:21
The error is kind of hidden in there, but it?s certainly not user friendly

mathias.duesterhoeft
2021-09-22 07:21
> If not, you should remove it from the pact test Do you mean "remove it from the contract"? My test is not providing metadata - but they are defined in the contract.

matt.fellows
2021-09-22 07:21
It would be better if Pact JS Core receieved structured validation errors, and then we could present it better

matt.fellows
2021-09-22 07:21
alternatively, we restrict the inputs - but the downside of that is we need to maintain what?s possible

tjones
2021-09-22 07:21
Interesting. I thought typescript only allowed `undefined` if it was explicitly set in the types, not just optional, but you're right.

tjones
2021-09-22 07:22
In that case it should behave appropriately. I'll update the code

matt.fellows
2021-09-22 07:22
One option Tim is to split the configuration - not just a single `Verifier` but to have a `PactBrokerVerifierConfiguration` and a `LocalPactVerifierConfiguration` etc. type thing with the appropriate options. That would give better type hints then

mathias.duesterhoeft
2021-09-22 07:23
I also scratched my head about that one - `pactBrokerUrl?: string` allows to pass `undefined`

matt.fellows
2021-09-22 07:23
the verifier could accept any of them, or we provide different verification methods

tjones
2021-09-22 07:23
So, we stopped verifying the combinations of options before sending them to the binary because the binary couldn't update what was valid without also requiring a change to pact-js (and all other frameworks). But, maybe what we should do is detect that it failed in this way (which we already do), and THEN run type verification.

matt.fellows
2021-09-22 07:23
the `?` means `undefined | string`

tjones
2021-09-22 07:24
This would mean that we'd go "it failed due to the wrong arguments - do we know why?"

tjones
2021-09-22 07:24
Yes, I think that type split is a good idea - although it only helps typescript users, so I think we should do it in code too.

tjones
2021-09-22 07:24
Also it means that for typescript users we have really unhelpful error messages

tjones
2021-09-22 07:25
it'll be like `pactBrokerUrl is not valid on the type <large confusing description of types>`

matt.fellows
2021-09-22 07:26
I always find having multiple types on a function arguments hard to read, so perhaps a separate function is actually better - each function accepts only a specific type


tjones
2021-09-22 07:27
That feels unhelpful, and will make migration harder

matt.fellows
2021-09-22 07:27
well, yes more specifically, remove it from the _consumer_ pact test

matt.fellows
2021-09-22 07:27
which, yes, will remove it from the contract

mathias.duesterhoeft
2021-09-22 07:27
Ah - I see - thanks.

tjones
2021-09-22 07:28
In the short term (next 20 minutes + 30 minutes release time) I will make it accept but warn if you say `pactBrokerUrl: undefined`

tjones
2021-09-22 07:30
Something like `The verifier option 'pactBrokerUrl' was explicitly set to undefined and will be ignored. This may be an error in your config. Remove the option entirely to get rid of this warning`

tjones
2021-09-22 07:36
Also, if we separate the types, we might prevent valid combinations. For example, you should be able to provide pacturls and a broker

matt.fellows
2021-09-22 07:36
Apologies, it really should have forced validation from the start, but we didn?t yet have the facility

matt.fellows
2021-09-22 07:37
that?s true. I was going to make the same case but got distracted by anohter thread :stuck_out_tongue:

tjones
2021-09-22 07:37
I think it'll get complex quickly. Even just with local vs remote, you could have the type be: ```PactBrokerVerifierConfiguration | LocalPactVerifierConfiguration | (PactBrokerVerifierConfiguration & LocalPactVerifierConfiguration)```

matt.fellows
2021-09-22 07:38
deferring validation to the core makes the most sense, and getting it to be helpful - this way all of the languages benefit and we do it once



mathias.duesterhoeft
2021-09-22 07:39
It makes sense I think.

mathias.duesterhoeft
2021-09-22 07:39
I was just searching for a quick fix. But properly validating the metadata is possible and increases the value of the test :+1:

matt.fellows
2021-09-22 07:59
I wanted to say ?we could look at an option to disable that? but I think it?s best we don?t. Once there is an assertion made on the consumer side, you would expect it to be verified!

tjones
2021-09-22 08:00
@mathias.duesterhoeft: v10.0.0-beta.51 is now cooking, let us know if you have any issues (it should be fully released in about 30-40 minutes)

matt.fellows
2021-09-22 08:04
Also, just reflecting on how much I :hearts: this:

mathias.duesterhoeft
2021-09-22 08:19
Btw - are `matchingRules` supported for `metaData` ? I have this but still the value itself is matched... ```"matchingRules": { "body": { //... }, "metaData": { "$.traceId: { "combine": "AND", "matchers": [{ "match": "type" }] }, } }, "metaData": { "traceId": "d3_7404" },```

matt.fellows
2021-09-22 08:21
good question. I actually didn?t think they were matchable, but it?s interesting that it let?s you do it

mathias.duesterhoeft
2021-09-22 08:25
My problem is that the matchers are not taken into account. For example the traceId in the metadata is different every time the consumer publishes the contract. So matching by value is just not feasible.

matt.fellows
2021-09-22 08:37
Could you please raise a request? It seems like something we should support

mathias.duesterhoeft
2021-09-22 08:38
Sure - would that be `pact-js` or `pact-js-core` ?

tjones
2021-09-22 09:11
Release is complete!

tjones
2021-09-22 09:25
Yeah, it has really helped with bug reports. I'm looking forward to overhauling all the logs so they're much nicer in general

matt.fellows
2021-09-22 11:24
Pact JS is fine, we?ll raise from there to wherever it needs to go

matt.fellows
2021-09-22 11:24
(probably needs to be exposed in the rust core)


matt.fellows
2021-09-22 11:46
Just saw it in #pact-js-development - thanks! :pray:

bryan
2021-09-22 14:03
@matt.fellows any advice here?

nrobison
2021-09-22 15:39
has joined #pact-js

sushant.soni
2021-09-22 15:51
Hello I am getting such error with the verification ``` $.data.products.0.meta.xyz.2 -> Expected 'DEQ17BY455455' to match '(.*?)'``` What am I missing?

sushant.soni
2021-09-22 16:05
For more info: The pact was generated from Pact-JVM a v3, and verified using pact-js@beta

calise
2021-09-22 17:06
has joined #pact-js

calise
2021-09-22 17:11
I'm getting the ENOENT error out of the box with the example project

calise
2021-09-22 17:15
Hi - I just tried to run the example project for node + jest consumer and I'm getting an ENOENT error from the pact-node-service. I'm not able to find anything on stackoverflow. I did a brief search here and found a suggestion to remove and reinstall node modules with latest node but that didn't work. Any suggestions?

calise
2021-09-22 17:26
I see that it's trying to spawn using darwin-1.88.63

calise
2021-09-22 17:27
And that binary does not exist in my node_modules folder

nrobison
2021-09-22 17:38
Hey folks. I have a question regarding number handling. We have a Java API that we're writing pacts against. One field returns either a number (e.g. 5000) or the string "Infinity". I tried to write a custom term for the field, but it's throwing type error. Any thoughts on this? Totally possible I'm doing it incorrectly. Here's my custom term: ```exhaustion: term({ matcher: "Infinity|^[+-]?([1-9]\\d*|0)(\\.\\d+)?", generate: 500000000 })```

matt.fellows
2021-09-22 20:35
Can you please share you npm install logs?

matt.fellows
2021-09-22 20:36
Are you on. Corporate machine? It's possible that artifact is being blocked

matt.fellows
2021-09-22 20:36
You can't write a regex for a number or a string

matt.fellows
2021-09-22 20:37
You need two tests - one for when it's a number and another for when it's Infinity

leonardo.viana
2021-09-22 20:38
Hi all. Any updates on approximately when pact-js v3 will be out of beta and released for generally availability?

sushant.soni
2021-09-22 20:45
@matt.fellows This works fine when the pact is v2. Do you know how can we work around this problem? or maybe even the root cause?

vicenzo
2021-09-22 21:36
:ok_hand:

matt.fellows
2021-09-22 22:04
Oh, sorry Bryan I missed this update

matt.fellows
2021-09-22 22:11
Could you please raise a request on the pact-js-core repo? We?ll look to bundle it into the actual package, so you don?t have to move it

matt.fellows
2021-09-22 22:12
currently, you can?t move the file elsewhere. That could also be done, but it would be better to not have to download it at all

matt.fellows
2021-09-22 22:55
Soon!

matt.fellows
2021-09-22 22:55
See https://github.com/pact-foundation/pact-js/projects/3, a lot of the bigger bits are done

matt.fellows
2021-09-22 22:59
The board is up to date, or very close to. You can see the remaining items before a release in the TODO column

matt.fellows
2021-09-22 22:59
Kudos to @tjones who?s been making some great progress

uglyog
2021-09-22 23:18
That is a strange regex. It will match everything, including nothing, and then capture the result

uglyog
2021-09-22 23:21
pact-js@beta is using a different regex implementation than pact-js v2. You might want to change your regex to be something like `[A-Z0-9]+`

sushant.soni
2021-09-23 07:43
Thanks, I?ll check this out.

nareshnavinash
2021-09-23 09:28
has joined #pact-js

radu.simu
2021-09-23 09:38
has joined #pact-js

aterrong
2021-09-23 09:42
has joined #pact-js

nisharaveendran30
2021-09-23 10:34
has joined #pact-js

sujithsukumaranm
2021-09-23 10:36
has joined #pact-js

sureshbabudevaki
2021-09-23 12:01
has joined #pact-js

greg.hinsley
2021-09-23 12:29
has joined #pact-js

bryan
2021-09-23 13:51
I?m not sure I?m making myself clear: in order to use pact in this company?s enterprise environment, the executables MUST be installed by Software Center? pact cannot install them

matt.fellows
2021-09-23 21:34
Sure, please raise a request then and we can look at it

matt.fellows
2021-09-23 21:35
I'd suggest looking at our beta, it doesn't use an executable and removes this need. We're closing in on releasing a major release of it

bryan
2021-09-23 21:48
what does it do in lieu of an executable?

bryan
2021-09-23 22:08
@matt.fellows

matt.fellows
2021-09-23 22:13
It uses a C library

bryan
2021-09-23 22:14
interesting? I?ll have to try it out on Monday and see if it works in this customer?s environment

thanuxxxx
2021-09-24 03:29
@matt.fellows So it seems like after `JVM version: 4.2.8,` the issue doesn't appear

matt.fellows
2021-09-24 03:34
thanks for following up

nyman.robin
2021-09-24 07:07
has joined #pact-js

francislainy.campos
2021-09-24 10:18
Hi, good morning. So I?m trying to run my pact tests but am getting this error. Thank you.

francislainy.campos
2021-09-24 10:20
```{ "name": "gatling_tool", "version": "0.1.0", "private": false, "dependencies": { "@ant-design/icons": "latest", "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", "@material-ui/lab": "^4.0.0-alpha.56", "@pact-foundation/pact-node": "^10.11.0", "@testing-library/user-event": "^7.2.1", "antd": "4.8.0", "axios": "^0.20.0", "bootstrap": "^4.5.2", "cors": "^2.8.5", "express": "^4.17.1", "hookrouter": "^1.2.3", "jquery": "^3.5.1", "moment": "^2.29.1", "popper.js": "^1.16.1", "react": "^16.13.1", "react-bootstrap": "^1.3.0", "react-csv": "^2.0.3", "react-dom": "^16.13.1", "react-dragger": "^1.3.0", "react-scripts": "3.4.3", "react-table": "^7.1.0", "startbootstrap-simple-sidebar": "^5.1.2" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "./node_modules/.bin/mocha 'src/pact_old/**/*.pact.js'", "eject": "react-scripts eject", "test:consumer": "mocha --exit --timeout 30000 src/draft/consumer.pact.spec.js", "test:provider": "mocha --exit --timeout 30000 provider.pact.spec.js", "publish": "npx pact-broker publish ./pacts --consumer-app-version 1.0.0-someconsumersha --tag master", "can-deploy:consumer": "npx pact-broker can-i-deploy --pacticipant gatling-consumer --version 1.0.0-someconsumersha --to prod", "can-deploy:provider": "npx pact-broker can-i-deploy --pacticipant gatling-provider --version 1.0.0-someprovidersha --to prod", "deploy:consumer": "npx pact-broker create-version-tag --pacticipant gatling-consumer --version 1.0.0-someconsumersha --tag prod", "deploy:provider": "npx pact-broker create-version-tag --pacticipant gatling-provider --version 1.0.0-someprovidersha --tag prod" }, "eslintConfig": { "extends": "react-app" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "@pact-foundation/pact": "^10.0.0-beta.21", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", "chai": "^4.2.0", "jest-pact": "^0.8.1", "mocha": "^8.1.3", "prop-types": "^15.7.2", "react-router-dom": "^5.2.0" } }```

ricardo.paquito
2021-09-24 10:36
has joined #pact-js

abramenkov.valentin
2021-09-24 12:42
has joined #pact-js

leo.tang
2021-09-24 17:56
has joined #pact-js

tjones
2021-09-24 22:15
Which version of the beta are you using? This "^10.0.0-beta.21" will select one of them - and it might be one of the broken ones.

tjones
2021-09-24 22:16
The latests is 10.0.0-beta.51, try that

tjones
2021-09-25 00:35
If you don?t need the spec version 3 features, then the main release (9.x.x) is the stable one

jyotiguptaofficial
2021-09-25 13:00
has joined #pact-js

jyotiguptaofficial
2021-09-25 13:04
Hi Folks, I am trying to run the pact test at react consumer side : https://github.com/thombergs/code-examples/tree/master/pact/pact-react-consumer [Repo Link] While running the pact at client side with command : yarn test:pact:graphql . I am getting following error. Can someone help for the same.

francislainy.campos
2021-09-25 14:33
Thank you. Yes, version 9 fixes this error. I get now a timeout issue when trying to run the tests from jest though but will open this as a separate question. Cheers.

francislainy.campos
2021-09-25 14:44
Hi, I?m getting this issue where the pact server does not appear to be running when I try to build a docker image. It works fine outside docker when I try yarn test:pact from there. https://github.com/francislainy/docker-sample/blob/master/Dockerfile https://github.com/francislainy/docker-sample/blob/master/src/pact/consumer/showcase/school.pact.test.js Any ideas please? Thank you.

tjones
2021-09-25 14:45
With docker we see longer start up times. Try increasing your test timeout

tjones
2021-09-25 14:46
if you're using jest, jest-pact does this for you

tjones
2021-09-25 14:48
this error looks like it is in your code, not in pact.

tjones
2021-09-25 14:48
can you share your code?

tjones
2021-09-25 14:48
Also, make sure you are awaiting or returning all promises appropriately


francislainy.campos
2021-09-25 14:50
Thank you Timothy. I?ve just tried now with 500000 as a timeout but got the same issue.

francislainy.campos
2021-09-25 14:50
I can try with jest-pact if you think this may be helpful to fix the problem.

tjones
2021-09-25 14:51
jest-pact automates the boiler plate. It might be helpful, but if you prefer to write it yourself, can you let us know: ? What version of pact-core / pact-js you are using ? What your test code is

francislainy.campos
2021-09-25 14:53
Sure, this is my code on github https://github.com/francislainy/docker-sample

francislainy.campos
2021-09-25 14:53
?@pact_foundation_greet/pact?: ?^9.16.1",

tjones
2021-09-25 14:57
The code looks right to me

tjones
2021-09-25 14:57
are you certain you are applying the new timeout correctly?

francislainy.campos
2021-09-25 14:57
```import { Matchers } from '@pact-foundation/pact'; import { getSchool } from '../../../apis/ids'; import providerBuilder, { PROVIDER } from '../../helpers/pactSetup'; const { somethingLike, uuid } = Matchers; const GET_EXPECTED_BODY = { name: somethingLike('InteractEd Test Eval School 1-91002661'), type: 'SCHOOL', sifRefId: uuid('54d2a3eb-0010-4988-9d41-ec68ea869399'), pid: somethingLike('91002661'), schoolId: uuid('54d2a3eb-0010-4988-9d41-ec68ea869399'), parentOrg: { orgId: uuid('fabe7fcc-6c79-4540-94ee-3f22072ddb7a'), name: somethingLike('InteractEd Test Eval District 1-91002660'), type: somethingLike('DISTRICT'), sifRefId: uuid('fabe7fcc-6c79-4540-94ee-3f22072ddb7a'), pid: somethingLike('91002660'), }, }; const provider = providerBuilder(PROVIDER); beforeAll(() => { return provider.setup().then((opts) => { process.env.API_PORT = opts.port; }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); describe('GET School', () => { beforeEach((done) => { const interaction = { state: 'i have a school', uponReceiving: 'a request for a school', withRequest: { method: 'GET', path: '/ids/v1/schools/0d2bf746-ae98-4bb4-a807-8c2db6d2852d', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('generate contract', async () => { const response = await getSchool( { schoolId: '0d2bf746-ae98-4bb4-a807-8c2db6d2852d' }, 'mockToken', { baseUrl: `${provider.mockService.baseUrl}/ids/v1`, }, ); expect(response.status).toEqual(200); } ,500000 ); });```

tjones
2021-09-25 14:58
What error do you get?

francislainy.campos
2021-09-25 14:58
That?s what I have it

tjones
2021-09-25 14:58
The error you originally posted in your screenshot is from the timeout in the hook, not the test

francislainy.campos
2021-09-25 14:59
I still get the same error

tjones
2021-09-25 14:59
Yes. This suggests your timeout is not being applied correctly.

tjones
2021-09-25 14:59
Please set jests timeout higher

francislainy.campos
2021-09-25 15:00
Where should I apply it if not there where I put the 50000?

tjones
2021-09-25 15:00
You can use jest-pact to do this, or you can pass it on the command line with `--testTimeout=30000`

tjones
2021-09-25 15:01
In the code you shared, you are setting the timeout on the individual test

francislainy.campos
2021-09-25 15:01
On the docker run command?

tjones
2021-09-25 15:01
It is better to change jest's timeout for all tests + hooks


tjones
2021-09-25 15:01
on jest

tjones
2021-09-25 15:01
Please see the jest documentation for timeouts

francislainy.campos
2021-09-25 15:09
The timeout is gone but the mock service is still not running

tjones
2021-09-25 15:12
As per the error message, see the logs to see what is going wrong

tjones
2021-09-25 15:13
it looks like the mock server isn't starting, so you should see an error message telling you what is going wrong

tjones
2021-09-25 15:14
if you see the startup message, but it's failing still, check your promises.

tjones
2021-09-25 15:14
Also, are you running tests in some sort of browser environment?

tjones
2021-09-25 15:16
That is saying the binaries weren't found.

francislainy.campos
2021-09-25 15:16
The logs are inside the docker container so I?d need to figure out how to access that as I?m still learning docker.

tjones
2021-09-25 15:16
Try deleting node_modules

tjones
2021-09-25 15:17
This log is enough - the problem is that pact doesn't have the binaries it is supposed to

francislainy.campos
2021-09-25 15:17
Which binaries?

tjones
2021-09-25 15:18
this sometimes happens if you install behind a corporate firewall

tjones
2021-09-25 15:18
pact installs these on `npm install`

tjones
2021-09-25 15:18
have a look further up in your logs to see if there were errors during npm install

tjones
2021-09-25 15:19
If you are behind a corporate firewall, you can tell pact to use local binaries following the instructions here: https://www.npmjs.com/package/@pact-foundation/pact-node#user-content-pact-download-location

francislainy.campos
2021-09-25 15:20
I?m not on vpn no


tjones
2021-09-25 15:20
Sorry, link didn't go directly correctly

tjones
2021-09-25 15:21
Can you see if the path to `pact-mock-service` in your error message resolves correclty?

tjones
2021-09-25 15:22
I have to go to bed here, but I will check back in the morning

francislainy.campos
2021-09-25 15:23
No problem. Thank you for your help.

francislainy.campos
2021-09-25 15:23
We can continue this whenever you?re back and have some more time.

tjones
2021-09-25 15:24
In summary: ? check for errors during `npm install` ? ensure that it works after you remove node_modules + package-lock (if these are corrupt, sometimes npm doesn't run the install script during `npm install`) ? see if the path to `pact-mock-service` from that error message resolves correctly

francislainy.campos
2021-09-25 15:24
No errors on npm no

francislainy.campos
2021-09-25 15:24
I?ll check the path

tjones
2021-09-25 15:25
Are you running npm install outside the container?

francislainy.campos
2021-09-25 15:25
No, docker

tjones
2021-09-25 15:25
Pact detects the architecture and installs the appropriate binaries, so if you run it outside it might not work


francislainy.campos
2021-09-25 15:25
```docker build -t docker-sample .```

tjones
2021-09-25 15:26
If you can make a minimal reproducible example docker file + repo, I can take a look tomorrow


francislainy.campos
2021-09-25 15:27
I?ll push the jest timeout change

tjones
2021-09-25 15:27
Your example has a mix of yarn and npm which probably isn't helping

francislainy.campos
2021-09-25 15:28
The docker commands I?ve been running are commented out inside the dockerfile

francislainy.campos
2021-09-25 15:28
yarn is what is triggering the test

tjones
2021-09-25 15:29
Right, but npm install is run, not yarn install

tjones
2021-09-25 15:29
some versions of yarn put the packages in different places to npm

francislainy.campos
2021-09-25 15:30
I can try with yarn install instead of npm install

francislainy.campos
2021-09-25 15:30
Anyways, please don?t feel obliged to keep replying to me if you want to go to bed

tjones
2021-09-25 15:31
Good luck! I'll check back tomorrow

jyotiguptaofficial
2021-09-25 15:31
I am trying to run the pact at react consumer end [Graphql] for the public repository, sharing the repo link https://github.com/thombergs/code-examples/tree/master/pact/pact-react-consumer.

francislainy.campos
2021-09-25 15:31
Sure, thank you. I?ll type here what happened and we can catch up when you?re back.

jyotiguptaofficial
2021-09-25 15:39
Test File : hero.service.test.graphql.pact.js Command for execution : cross-env CI=true react-scripts test --runInBand --setupFiles ./pact/setup-graphql.js --setupTestFrameworkScriptFile ./pact/jest-wrapper.js --testMatch \?**/*.test.graphql.pact.js\?

jyotiguptaofficial
2021-09-25 15:39
Setup-graphql.js: ```const path = require('path'); const Pact = require('@pact-foundation/pact').Pact; global.port = 8080; global.provider = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'graphql-hero-consumer', provider: 'graphql-hero-provider', host: '127.0.0.1' });```

jyotiguptaofficial
2021-09-25 15:40
jest-wrapper.js: ```beforeAll((done) => { global.provider.setup().then(() => done()); }); afterAll((done) => { global.provider.finalize().then(() => done()); });```

jyotiguptaofficial
2021-09-25 15:41
Test File : hero.service.test.graphql.pact.js : ```import GraphQLHeroService from './hero.service.graphql'; import * as Pact from '@pact-foundation/pact'; import fetch from 'node-fetch'; describe('HeroService GraphQL API', () => { const heroService = new GraphQLHeroService('http://localhost', global.port, fetch); // a matcher for the content type "application/json" in UTF8 charset // that ignores the spaces between the ";2 and "charset" const contentTypeJsonMatcher = Pact.Matchers.term({ matcher: "application\\/json; *charset=utf-8", generate: "application/json; charset=utf-8" }); describe('getHero()', () => { beforeEach((done) => { global.provider.addInteraction(new Pact.GraphQLInteraction() .uponReceiving('a GetHero Query') .withRequest({ path: '/graphql', method: 'POST', }) .withOperation("GetHero") .withQuery(` query GetHero($heroId: Int!) { hero(id: $heroId) { name superpower __typename } }`) .withVariables({ heroId: 42 }) .willRespondWith({ status: 200, headers: { 'Content-Type': contentTypeJsonMatcher }, body: { data: { hero: { name: Pact.Matchers.somethingLike('Superman'), superpower: Pact.Matchers.somethingLike('Flying'), __typename: 'Hero' } } } })).then(() => done()); }); it('sends a request according to contract', (done) => { heroService.getHero(42) .then(hero => { expect(hero.name).toEqual('Superman'); }) .then(() => { global.provider.verify() .then(() => done(), error => { done.fail(error) }) }); }); }); });```

jyotiguptaofficial
2021-09-25 15:42
GraphQLHeroService : ```import {ApolloClient} from "apollo-client" import {InMemoryCache} from "apollo-cache-inmemory" import {HttpLink} from "apollo-link-http" import gql from "graphql-tag" import Hero from "../hero"; class GraphQLHeroService { constructor(baseUrl, port, fetch) { this.client = new ApolloClient({ link: new HttpLink({ uri: `${baseUrl}:${port}/graphql`, fetch: fetch }), cache: new InMemoryCache() }); } getHero(heroId) { if (heroId == null) { throw new Error("heroId must not be null!"); } return this.client.query({ query: gql` query GetHero($heroId: Int!) { hero(id: $heroId) { name superpower } } `, variables: { heroId: heroId } }).then((response) => { return new Promise((resolve, reject) => { try { const hero = new Hero(response.data.hero.name, response.data.hero.superpower, null, heroId); Hero.validateName(hero); Hero.validateSuperpower(hero); resolve(hero); } catch (error) { reject(error); } }) }); }; } export default GraphQLHeroService;```

jyotiguptaofficial
2021-09-25 16:03
Hey @tjones Can you pls help me on the same

francislainy.campos
2021-09-25 16:15
Hi, so it?s working now. Removed npm install and added yarn install to the scripts file and that fixed the issue.

francislainy.campos
2021-09-25 16:15
Thanks very much for your help.

mattandaey
2021-09-25 20:32
has joined #pact-js

matt.fellows
2021-09-25 21:54
Hi Jyoti, note that this is a global workspace and people are from all over the world. No need to @ somebody who's responded they'll be notified and will respond if they choose to. Tim was probably asleep at the time! :rolling_on_the_floor_laughing:

tjones
2021-09-26 02:44
Glad you got it working. npm and yarn sometimes look in different places for their packages, so it's best to stick to one or the other.

tjones
2021-09-26 02:48
There are a few issues here. Probably the real cause is being masked because of the way `done` is used - if you are using `done` with promises, you'll have to remember to catch and fail if there are errors. The last test block has a catch, but it's in the wrong place.

tjones
2021-09-26 02:48
To reduce the risk of having bugs in your tests, it's usually better practice to return promises instead of using `done`

tjones
2021-09-26 02:51
Also, when you have the test wrapper globally like that, you'll have the pact server started up for every test. This is probably not what you want - and means that the logs can be hard to interpret. For example, in your log, I can see the pact server appearing to start, but it might not be during the test that's failing. I suspect that further up in your log you have a failing pact server start, which might be the issue

tjones
2021-09-26 02:52
We introduced jest-pact to help reduce the boilerplate setup for jest, and to ensure that it's in the most helpful place. Not using jest-pact isn't the problem, but it would bring these refactorings for you for free.

tjones
2021-09-26 02:52
Try running with `logLevel: 'debug'`

tjones
2021-09-26 02:56
If you want a quick fix to ensure that you're only starting the pact server when you need to, try moving the `beforeAll` and `afterAll` out of the wrapper script and into the pact test file. You don't want it in the wrapper script because it will run on all tests.

jyotiguptaofficial
2021-09-26 08:41
Thanks for the help. Really appreciated. I have integrated with jest-pact, it helped to remove all setup/wrapper files required for test execution. Moreover consuming async/await for the async task execution now by removing the done callback.

jyotiguptaofficial
2021-09-26 08:45
Hey Folks, please help with this query. Thanks in advance. Is there any way for addInteraction of GraphQLInteractionObject in jest-pact. As I am forced to use only InteractionObject as parameter in provider.addInteraction function. Sharing code snippet for better clarity

jyotiguptaofficial
2021-09-26 08:45
```//Customer.pact.graphql.test.js import { pactWith } from 'jest-pact'; import path from 'path'; import { provideApolloClient, useQuery } from '@vue/apollo-composable'; import { getCustomerRequest, getCustomerResponse } from './customerInteraction'; import getCustomer from '../../../../src/graphql/queries/customers/getCustomer'; import apolloClient from '../../../../src/plugins/apollo'; const CONSUMER = 'Calypso Get Consumer'; const PROVIDER = 'GraphQL'; const PACTConfigOption = { cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'DEBUG', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: CONSUMER, provider: PROVIDER, host: 'localhost', }; pactWith(PACTConfigOption, (provider) => { describe('Get Customer GraphQL', () => { beforeEach(async () => { const interaction = { state: 'customer query', ...getCustomerRequest, willRespondWith: getCustomerResponse, }; await provider.addInteraction(interaction); }); it('generate contract for getCustomer', async () => { provideApolloClient(apolloClient); const { result, error } = await useQuery(getCustomer, { customerId: '2135e729-a289-49e5-9c22-b0ffba629e24' }); expect(result).toEqual(''); // expect(error).toEqual(''); }); }); });```

jyotiguptaofficial
2021-09-26 08:47
// CustomerInteraction.js File ```import { Matchers } from '@pact-foundation/pact'; const { somethingLike, uuid, } = Matchers; const contentTypeJsonMatcher = Matchers.term({ matcher: 'application/json; *charset=utf-8', generate: 'application/json; charset=utf-8', }); export const getCustomerRequest = { uponReceiving: 'a getCustomer Query', withRequest: { method: 'POST', path: '/graphql', body: { operationName: 'getCustomer', variables: { customerId: uuid('54d2a3eb-0010-4988-9d41-ec68ea869399'), }, query: 'query getCustomer($customerId: ID) {n customer(id: $customerId) {n namen idn __typenamen }n}n', }, }, }; export const getCustomerResponse = { status: 200, headers: { 'Content-Type': contentTypeJsonMatcher, }, body: { data: { customer: { name: somethingLike('customer name'), }, }, }, };```

tjones
2021-09-26 10:15
the provider in `jest-pact` is the same as the provider from pact-js - all jest-pact does is give you a wrapper for the boilerplate,


jyotiguptaofficial
2021-09-26 11:48
Yeah, I got it. Make sense. Thanks alot!!!

abubics
2021-09-27 00:53
:taco: for @tjones \o/

matt.fellows
2021-09-27 01:09
yes, absolutely more :taco: for @tjones

univ.anirudh
2021-09-27 06:09
Is there anything in particular I need to do for a request payload to be sent as JSON when verifying a contract on the provider's side? The body of the request seems to be getting sent as a key-value pair with key as the actual payload and value as an empty string

univ.anirudh
2021-09-27 06:09
The pact on the consumer side for reference - ``` { "description": "a get-room request", "providerState": "there exist some rooms", "request": { "method": "POST", "path": "/", "headers": { "Accept": "application/json" }, "body": { "content": { "api": "get-room", "request": { "roomHash": "foobar" } }, "meta": { } } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "success": false } } },```

univ.anirudh
2021-09-27 06:11
~When sending normal requests to the same endpoint, the payload gets converted to JSON by a middleware, but that seems to be failing for requests through the verification mock server~ Can be ignored. I was missing a `Content-Type` header in the pact json which was implicitly being sent as `application/json` . Didn't realize that it has to be explicitly set in the contract. My bad!

tjones
2021-09-27 07:41
Perhaps we should make the consumer pact warn if there is no content type :thinking_face:

saurelio58
2021-09-27 12:39
has joined #pact-js

francisco
2021-09-27 18:27
has joined #pact-js

jamesatroughton
2021-09-28 10:42
has joined #pact-js

leonardo.viana
2021-09-28 22:06
Hi all. So, I understand we can verify all pacts with a given tag by using something like: ```consumerVersionSelectors: [ { tag: "prod", all: true } ]``` Now, is it possible to verify the _latest_ version of the pacts from _all_ tags?

jake.thacker
2021-09-28 22:06
has joined #pact-js

craig.schwarzwald
2021-09-28 22:37
has joined #pact-js

tjones
2021-09-29 00:45
I think you can just do `[{ latest: true }]`

tjones
2021-09-29 00:46
tbh, I'm not 100% sure - pact-js just passes whatever selector you give it on to the broker, and it decides

owain.hunt
2021-09-29 12:58
has joined #pact-js

bryan
2021-09-29 14:06
@matt.fellows I haven?t been able to try the beta because their internal nexus npm repository has the beta quarantined :disappointed:

damtsisa
2021-09-30 06:58
has joined #pact-js

morsisdivine
2021-09-30 09:23
has joined #pact-js

patrice.jy.thomas
2021-09-30 15:05
has joined #pact-js

kschendster
2021-09-30 16:46
has joined #pact-js

adam.dubnytskyy
2021-09-30 17:49
has joined #pact-js

stefano.varesi
2021-09-30 17:51
has joined #pact-js

steven.yi
2021-09-30 20:17
has joined #pact-js

leonardo.viana
2021-09-30 21:49
It seems to me that using `[{ latest: true }]` would just verify the latest overall pact (regardless of tag), *not* the latest pacts for each and every tag. @matt.fellows, in minute 11:30 of video https://www.youtube.com/watch?v=6Qd-kq1AzZI (during the provider pipeline) you say that: > ?pact is going to the pact broker pull down all the contracts? How do I specify ?the latest pacts from all tags? via `consumerVersionSelectors`? Is there someone who would know the answer to that question?

matt.fellows
2021-09-30 21:55
I don't think there is a selector for "all tags". That could mean hundreds of pacts and will just grow unless you delete old ones. Can you explain why you want it?


leonardo.viana
2021-09-30 22:13
Yeah, I saw that link, but it seems incomplete, given that the `all` property is not even listed there. What happens when `consumerVersionSelectors` is not specified at all? Will it just select the latest overall pact? I didn?t see that in the documentation either?

calcorbin
2021-09-30 23:09
has joined #pact-js

tjones
2021-09-30 23:19
This is probably a #pact-broker question

matt.fellows
2021-09-30 23:22
probably, can you explain why you want that use case though Leonardo? I ask because it is the kind of thing that could accidentally lead to strange/bad behaviour

osikwemhev
2021-10-01 01:45
has joined #pact-js

kentaro
2021-10-01 10:05
has joined #pact-js

vitali.domashkevitsh
2021-10-01 10:08
has joined #pact-js

seb983
2021-10-01 11:30
has joined #pact-js

dimundo
2021-10-01 12:18
with 9.16.3 i?m getting ```.../.yarn/unplugged/@pact-foundation-pact-node-npm-10.13.8-8690d7b85e/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact-1.60.0/lib/pact/hal/entity.rb:102:in `assert_success!': Error retrieving https://pact.xxx.xxx/ status=404 default backend - 404 (Pact::Hal::ErrorResponseReturned)```

matt.fellows
2021-10-01 12:23
We do run some feature examples that publish/verify from a broker in the Pact JS repo. What action are you performing Dmitry? @bethskurrie any ideas as to what this could be?

dimundo
2021-10-01 12:25
provider fetching pacts from broker

matt.fellows
2021-10-01 12:33
Any chance you could please add the verbose flag? Might need to collectively fix it tomorrow with fresh eyes rather than rush another out

dimundo
2021-10-01 12:39
i?m kinda also on coffee , can you elaborate how to do it more verbose ? :smile:

dimundo
2021-10-01 12:39
some key somewhere ?

vannessa.andrade
2021-10-01 14:44
has joined #pact-js

calcorbin
2021-10-01 17:39
Let me know if you all have more issues you'd like me to work on for pact-js, I've had fun so far!

leonardo.viana
2021-10-01 20:14
Hi all. I?m using `consumerVersionSelectors` with pact-js v3 beta and the `tag` I specify seems to be getting ignored. For example, if I specify `consumerVersionSelectors: [ { tag: 'dev_lviana_pact', latest: true } ]`, it simply verifies the latest version, ignoring tags, as can be seen from the output (notice how the tag is *not* mentioned in the output): ```The pact at https://menloinfra.pactflow.io/pacts/provider/pnr-policy/consumer/menlo-frontend-policy/pact-version/c3e484fb28acdba797b9674f88f9c9fc3dbfed24 is being verified because the pact content belongs to the consumer version matching the following criterion: * latest version of menlo-frontend-policy that has a pact with pnr-policy (2.81.0-3-12-gd6d0eb7e2)``` As a matter of fact, the issue I?m seeing seems to be exactly like the one described below: https://github.com/pact-foundation/pact-js/issues/713 Now, that issue was supposedly fixed on version `10.0.0-beta.44`: https://github.com/pact-foundation/pact-js/commit/f8e511fbc0a006bde4599308d377844830a31bcd The thing is, version `10.0.0-beta.44` is exactly the version I?m using, and yet I?m still seeing this issue. Am I missing something, or is it possible that the `tag` property is still being ignored in recent versions of pact-js v3 beta?

matt.fellows
2021-10-01 22:39
Just confirming you did figure this one out and it's sorted now? K8s change?

matt.fellows
2021-10-01 23:21
Can you please respond to that ticket with a debug level log so we can take a look at what?s happening?

leonardo.viana
2021-10-02 00:11
@matt.fellows, I just did that. You can clearly see that `consumerVersionSelectors` is an empty array with `10.0.0-beta.44`, even though I passed in `consumerVersionSelectors: [ { tag: 'dev_lviana_pact', latest: true } ]`.

leonardo.viana
2021-10-02 00:17
Here it is for your reference:

matt.fellows
2021-10-02 00:50
Thanks. I would just update to the latest and see if it was fixed in between. There were a few build issues whilst we tried to add support for node 16. We're up to 51 now

matt.fellows
2021-10-02 00:51
FYI we've made really good progress in the v3 branch in the past few weeks, I'd say we're a week or two away from revisiting the API in the v3 branch and getting close to the next major release. Thanks for your patience! :pray:

mickfagan
2021-10-02 10:36
has joined #pact-js

maxim.matviyuk
2021-10-03 16:48
has joined #pact-js

jonathan.a.stern
2021-10-03 20:38
has joined #pact-js

dimundo
2021-10-04 06:15
yes, everything is fine now :slightly_smiling_face:

matt.fellows
2021-10-04 06:16
phew!

matt.fellows
2021-10-04 06:16
this kind, or the better kind? :stuck_out_tongue:

dimundo
2021-10-04 06:16
yes :troll:

matt.fellows
2021-10-04 06:16
:laughing:

chris.ramsden
2021-10-04 16:40
has joined #pact-js

leonardo.viana
2021-10-04 20:20
I noticed that `consumerVersionTags` seems to work on `beta.44`. Also, `consumerVersionSelectors` does indeed seem to work on `beta.51`, so it looks like we are good.

matt.fellows
2021-10-04 21:17
great, thank you for confirming!

tausif2909
2021-10-05 04:32
Hello, my pact publishing suddenly started failing in the jenkins pipeline with error : `[2021-10-01T10:11:49.048Z] INFO: pact-node@6.21.3/23527 on ip-10-62-220-138: Checking if it it possible to deploy` `[2021-10-01T10:11:49.051Z] INFO: pact-node@6.21.3/23527 on ip-10-62-220-138: Asking broker at https://pact.xyz.net/ if it is possible to deploy` `[2021-10-01T10:11:49.061Z] INFO: pact-node@6.21.3/23527 on ip-10-62-220-138: Created './standalone/linux-x64-1.63.0/bin/pact-broker can-i-deploy --pacticipant 'flex-taxonomy-service' --version '1.0.0' --pacticipant 'flex-search-app' --version '1.0.0' --broker-base-url 'https://pact.xyz.net/'' process with PID: 23539` `[2021-10-01T10:12:00.213Z] WARN: pact-node@6.21.3/23527 on ip-10-62-220-138: Pact exited with code 1.` `[2021-10-01T10:12:00.214Z] ERROR: pact-node@6.21.3/23527 on ip-10-62-220-138:` `can-i-deploy did not return success message:` `Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=error: certificate verify failed /var/lib/jenkins/workspace/ps_FMP_UI_flex-search-app_master/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/matrix.rb:13:in `get', attempt 1 of 3` what could be the issue? my pact portal is working fine, I am able to publish it from my local

tjones
2021-10-05 04:33
Can you try updating to the latest version of pact?

tjones
2021-10-05 04:34
There is an issue with some expired SSL certs

matt.fellows
2021-10-05 04:34
Yep, probably Let's encrypt issue

tausif2909
2021-10-05 04:34
~Below are the logs~

tausif2909
2021-10-05 04:39
right now its `"@pact-foundation/pact-node": "^6.21.3"` , should I upgrade it to `9.x.x`?

tausif2909
2021-10-05 04:40
latest is `Release v9.16.3`

tausif2909
2021-10-05 04:42
another one is `"pact": "^4.3.2"` , Sorry but I am not sure which one to upgrade

brian.fung
2021-10-05 04:57
has joined #pact-js

matt.fellows
2021-10-05 04:59
they are both? old

matt.fellows
2021-10-05 04:59
at a minimum, you need to have `pact-node` updated to the very latest

matt.fellows
2021-10-05 04:59
which is `v10.13.8`

matt.fellows
2021-10-05 05:00
`pact` is currently `v9.16.3` as you have observed

matt.fellows
2021-10-05 05:00
I would recommend updating Pact. If you have `pact-node` as an explicit dependency, you could probably remove it (`pact` brings it in anyway)

matt.fellows
2021-10-05 05:00
if there are upgrade teething issues, I would then see if you can update `pact-node` independently of `pact`

tausif2909
2021-10-05 05:02
perfect, thanks @matt.fellows @tjones

tjones
2021-10-05 05:03
pact-node isn't intended to be depended on directly, although there were a lot of old examples that did depend on it

tjones
2021-10-05 05:03
if you're using it, you probably have custom scripts that use it that could be replaced with CLI commands

tjones
2021-10-05 05:04
Please let us know if you have any issues with the upgrade

elekberhacizade
2021-10-05 05:27
has joined #pact-js

ankit.wadhwana
2021-10-05 12:23
has joined #pact-js

zhaopeng
2021-10-05 12:24
has joined #pact-js

bjorn.johansson
2021-10-05 13:16
has joined #pact-js

pcting
2021-10-05 18:57
has joined #pact-js

aulia.ahn
2021-10-06 00:01
has joined #pact-js

muralis
2021-10-06 01:21
has joined #pact-js

tausif2909
2021-10-06 06:57
I have upgraded pact to `9.16.3` , but now my code returns error while generating pact like : `TypeError: provider.addInteraction is not a function`

tausif2909
2021-10-06 06:58
Have we stopped supporting `provider.setup` & `provider.addInteraction` in latest version

lakapoor777
2021-10-06 08:47
has joined #pact-js

tausif2909
2021-10-06 08:57
sorry , Please ignore.. replied in the wrong thread

tausif2909
2021-10-06 08:58
I have upgraded pact to `9.16.3` , but now my code returns error while generating pact like : `TypeError: provider.addInteraction is not a function`

tausif2909
2021-10-06 08:58
Have we stopped supporting `provider.setup()` & `provider.addInteraction()` in latest version

matt.fellows
2021-10-06 09:47
No, they are still there

matt.fellows
2021-10-06 09:47
Please share your logs and/or code

garry.jeromson973
2021-10-06 09:52
has joined #pact-js

tausif2909
2021-10-06 10:10
sorry it was my bad in the declaring variable.. sorted out the issue. thanks

tausif2909
2021-10-06 10:25
After upgrading to the latest still getting SSL certificate error

tausif2909
2021-10-06 10:29
```tausif@tausif:~/git-directories/my-search-app/Service/publishPact$ node publishToPactBroker.js [2021-10-06 10:22:09.623 +0000] INFO (30582 on tausif): pact-node@10.13.8: Publishing Pacts to Broker [2021-10-06 10:22:09.626 +0000] INFO (30582 on tausif): pact-node@10.13.8: Publishing pacts to broker at: https://pact.xyz.net/ [2021-10-06 10:22:11.065 +0000] WARN (30582 on tausif): pact-node@10.13.8: Pact exited with code 1. [2021-10-06 10:22:11.065 +0000] ERROR (30582 on tausif): pact-node@10.13.8: Could not publish pact: /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `connect' : SSL_connect returned=1 errno=0 state=error: certificate verify failed ( OpenSSL::SSL::SSLError ) from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `block in connect' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/timeout.rb:74:in `timeout' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `connect' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:863:in `do_start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:852:in `start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:79:in `block in perform_request' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:93:in `until_truthy_or_max_times' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:64:in `perform_request' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:25:in `get' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/link.rb:41:in `get' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/link.rb:45:in `get!' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal_client_methods.rb:20:in `index_resource' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/publish_pacts.rb:31:in `call' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/publish_pacts.rb:14:in `call' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/cli/broker.rb:157:in `publish_pacts' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/cli/broker.rb:42:in `publish' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/base.rb:485:in `start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/cli/custom_thor.rb:15:in `start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/app/pact-broker.rb:34:in `<main>' Something went wrong while pushing pact for collections Error: /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `connect' : SSL_connect returned=1 errno=0 state=error: certificate verify failed ( OpenSSL::SSL::SSLError )``` Logs

matt.fellows
2021-10-06 11:47
Please see the pinned issue on pact JS for solution

matt.fellows
2021-10-06 11:47
There is still work to fully resolve

tausif2909
2021-10-06 12:18
:+1:

matt.fellows
2021-10-06 12:23
:wave: hi folks, the organiser of https://testjssummit.com/ reached out about doing a talk on Pact. I don?t have the capacity to put together a new talk right now and wouldn?t want to repeat my usual _yet another time._ If anybody is keen, i?d be happy to do an intro - let me know! If it helps, here are some ideas: 1. Talk about your journey. People love a good story to connect with 2. Talk about how you used Pact in some obscure technology, or something not often presented (messaging, graphql, AWS/cloud etc.) 3. Show how to refactor an existing application to be testable with Pact 4. Metrics, outcomes and killer headlines (ala https://building.nubank.com.br/why-we-killed-our-end-to-end-test-suite/) :laughing:

anagha.sulakhe
2021-10-06 16:27
has joined #pact-js

carolyn.biggar
2021-10-07 00:27
has joined #pact-js

tausif2909
2021-10-07 04:59
Sorry to ask you but do you have any ETA to fix this issue or any workaround to temporary fix to avoid SSL error? As our multiple builds are failing in the pipeline @matt.fellows @tjones


tjones
2021-10-07 05:00
> The short term resolution is to disable SSL verification with the env var PACT_DISABLE_SSL_VERIFICATION=true or setting one of standard openssl SSL_CERT_FILE or SSL_CERT_DIR env vars.


tausif2909
2021-10-07 05:04
Thanks @tjones

mesut.gunes
2021-10-07 09:03
has joined #pact-js

vandana.bhaskersen
2021-10-08 09:58
has joined #pact-js

ad.redouani
2021-10-09 15:11
has joined #pact-js

amulyadoss
2021-10-09 21:09
has joined #pact-js

amulyadoss
2021-10-09 21:53
I am working on a Pact test where the service under test has as a required field cookie in header, whose value is the xsrf token. This service is using axios post to make the request. The other required fields to be sent in the header are the content-type and x-xsrf-token. I created the header as follows: headers: { cookie:?XSRF-TOKEN=123?, Content-type:'application/json' X-xsrf-token:?123? } The problem that I am facing is that the pact test is failing with the following error: Could not find key ?cookie?(keys present are: Content-type,X-xsrf-token) at $.headers I am able to verify that the pact test is sending the cookie in the header and also that the service is receiving it. It is only when it makes the http://axios.post call that the cookie is being dropped. I have tried all the fixes suggested:withCredentials:true, expose headers etc but the error is always that the cookie key is not in the header. Can someone please help me with this as I am all out of ideas.

matt.fellows
2021-10-09 22:40
Is this a consumer test or a provider test?

amulyadoss
2021-10-09 22:42
This is a consumer test.

matt.fellows
2021-10-09 22:43
Can you please post the entire pact test?

amulyadoss
2021-10-09 22:49
Thank you! Will do

amulyadoss
2021-10-09 23:20
const NFWServiceTest: PactTestDefinition=[ function defineInteraction(){ return { uponReceiving:?a request to send postal mail?, withRequest:{ method:?POST?, path:?/orders?, body:mockRequestBody ///JSON object }, willRespondWith:{ status:200, headers:{?Content-Type?:?application/json?} body:mockResponse //json object } }; }, function(pactHost){ It(?Request returns 200?, async done =>{ const mockThis = { headers: { ?cookie?:?XSRF-TOKEN=123?, ?Content-Type?:'application/json?, ?X-xsrf-token?:?123? } //Following is for Falcor routes- //service uses falcor & axios //This is Falcor call const callRoute:CallRoute = NFWService.sendPostalMail; //This is the Falcor path set const pathSet:any=[?nfw?,?ALL?], // this resolves to ?http://127.0.0.0.1:1231/orders%E2%80%99 URLS.WEBSERVICE_URL=pactHost +?/orders?; const actualResponse:any=await callRoute.call.call(mockThis,[pathSet],[mockRequestBody]); const actualVal:any=actualResponse.value.value; expect(actualValue).toEqual(mockResponse); done(); }); } ]; //passing it to a wrapper that generates the pact file PactTest(NFWRoute.sendPostalMail,?provide-api-name?,NFWServiceTest);

amulyadoss
2021-10-09 23:20
The service is using Falcor and the actual http post call is made by axios

amulyadoss
2021-10-09 23:23
Also we are using an in-house wrapper PactTest to set up & tear down jest tests, as well as all the pact related set up like log level, pact host etc.

amulyadoss
2021-10-09 23:25
I have successfully been able to write consumer pact tests for services which are using Falcor and axios. However none of those services had a cookie in the header as a required field.

matt.fellows
2021-10-09 23:28
I'm confused about the use of mockThis, but could you please also set the logs to debug and share the pact log file created?

matt.fellows
2021-10-09 23:29
Also for future ref, please try and format your code with code gates

matt.fellows
2021-10-09 23:29
(I'm on mobile FYI so may miss something)

amulyadoss
2021-10-09 23:30
mockThis is just a const for the header. I could have just used const headers as well.

matt.fellows
2021-10-09 23:32
Oh, which version of pact are you using?

matt.fellows
2021-10-09 23:35
If you're using the beta please set to verbose and upload a test file of your terminal log output

amulyadoss
2021-10-10 00:16
In the log , I have console logged the headers being sent in the pact test and what the incoming header in the service is. Also have logged the request options that are used to make the axios post call.

matt.fellows
2021-10-10 00:45
Thanks, but I need the log file, it should be in the relative path like logs/pact.log by default

matt.fellows
2021-10-10 00:46
That will tell us what actual req/res was received by the mock service

matt.fellows
2021-10-10 00:46
Separate to the terminal output

amulyadoss
2021-10-10 01:17
Sadly I don?t have access to the log file, because I am unable to run the pact test locally. The pact test runs as a part of a bamboo build stage. Sorry, I know i am not providing any useful info. Any advise on what to look for to help debug the issue?

matt.fellows
2021-10-10 01:18
You should get the log file to be a build artifact then

matt.fellows
2021-10-10 01:19
As for your test, the obvious thing missing to me is that I can't see anywhere in your pact test where you tell pact it's expecting an xsrf header. I.e. there are no expectations set on the headers property if the pact Interaction. Are you putting the expectation on the body?

matt.fellows
2021-10-10 01:19
Specifically, the expectation should be on the request header

amulyadoss
2021-10-10 01:30
Thank you I did have the headers here in the given

amulyadoss
2021-10-10 01:32
withRequest:{ method:?POST?, path:?/orders?, headers:{'cookie':'xsrf-token=123','content-type':'application/json','x-xsrf-token':'123'} body:mockRequestBody ///JSON object },

amulyadoss
2021-10-10 01:33
but it didnt seem to make any difference. It looks like the post call was failing with a 500, bcos the cookie is missing.

matt.fellows
2021-10-10 01:48
Is this the same as the other test? It looks different

matt.fellows
2021-10-10 01:49
Why can't you run this locally?

matt.fellows
2021-10-10 01:49
Pact tests are unit tests

matt.fellows
2021-10-10 01:50
The pact log file will tell you exactly what you configured and exactly what you sent

matt.fellows
2021-10-10 01:51
Because you have a number of tools/layers that are in between it's very hard to help you without them

amulyadoss
2021-10-10 01:55
I will try to find it. The reason I am not able to run it locally, is I am running it on a windows machine and I get an error thrown by Ruby about the path being too large.

matt.fellows
2021-10-10 01:56
Ah!

matt.fellows
2021-10-10 01:57
Have you tried moving the project closer to e.g C: ?

matt.fellows
2021-10-10 01:57
The v3 beta might be worth looking into

farshad.falaki
2021-10-10 19:13
has joined #pact-js

jhopkinwilliams
2021-10-12 02:01
has joined #pact-js

josephhaig
2021-10-12 08:52
has joined #pact-js

margarita.lukjanska
2021-10-12 10:12
has joined #pact-js

oak155online
2021-10-12 14:17
has joined #pact-js

filipovic
2021-10-13 06:51
has joined #pact-js

stefan.smith
2021-10-13 09:37
has joined #pact-js

warren
2021-10-13 16:45
has joined #pact-js

michael.stein
2021-10-13 19:02
has joined #pact-js

hwillj
2021-10-14 14:52
has joined #pact-js

craig.schwarzwald
2021-10-14 17:57
I'm trying to run my consumer pact test locally on Windows and getting: ...pact-node/standalone/win32-1.88/pact/lib/ruby/lib/Ruby/gems/2.2.0/gems/builder1.9.9/lib/builder.rb:418:in []=': Invalid argument - ruby_setenv(GEM_PATH) This error only comes up on Windows and works fine on my Linux build pipeline. From Google searches it looks like something in my ENV is too large. I've tried wrapping the pact command in a bash script to eliminate my INCLUDE, CLASS PATH, and shortening my PATH to bare minimum, but still facing this error. Does anyone else have any other ideas?

matt.fellows
2021-10-14 22:15
do you happen to also have Ruby installed on your system?

matt.fellows
2021-10-14 22:15
I?ve seen cases where there are some extra environment variables that can interfere with things

matt.fellows
2021-10-14 22:15
but have not seen that specific error before

matt.fellows
2021-10-14 22:16
We?re edging closer to a release of our new beta interface: https://github.com/pact-foundation/pact-js/tree/master#pact-js-v3

matt.fellows
2021-10-14 22:16
We are blocked by an upstream problem at the moment, so it?s still a few months away, but that should resolve that specific issue

matt.fellows
2021-10-14 22:16
(doesn?t use Ruby anymore)

fengniy
2021-10-15 02:09
has joined #pact-js

craig.schwarzwald
2021-10-15 03:16
Yeah, I'm trying to keep an eye out for the Pact JS V3 release. I'm not sure I can get a beta inside my company.

craig.schwarzwald
2021-10-15 03:17
I shouldn't have Ruby installed anywhere.

matt.fellows
2021-10-15 05:04
I thought that might be the case

mark.dathorne
2021-10-15 09:51
has joined #pact-js

matt.fellows
2021-10-15 10:17
have you tried inspecting your env to see what?s in there? I?m assuming you won?t be able to share that, but I wonder what a trial/error might look like

matt.fellows
2021-10-15 10:17
I can?t even find that file on the internet :stuck_out_tongue:

matt.fellows
2021-10-15 10:17
will have to download the package itself

artur
2021-10-15 12:24
I'm trying to migrate from v3 beta 44 to 51 and the provider states are not fired `MismatchResult::Error("Invalid status code: 500", None)` any idea what the issue could be?

craig.schwarzwald
2021-10-15 13:32
There are a total of 61 variables in my ENV it looks like. The only 3 that are more than 20 or so characters are INCLUDE, CLASS PATH, and PATH, which I've wiped out or minimized in a bash script before the line that executes the pact test.

craig.schwarzwald
2021-10-15 13:40
Hmmm, just tried to export all other variables to "" as well, but still getting that same error.

haroldlearning93
2021-10-15 14:49
has joined #pact-js

vsrungar95
2021-10-15 22:14
has joined #pact-js

tjones
2021-10-16 00:17
It sounds like the provider state handler is returning a 500. Are you able to share your state handler code?

artur
2021-10-16 10:31
``` 'the user is recreated': (setup, parameters) => { const email = `${parameters.username}@example.com` if (setup) { fetch(providerBaseUrl + '/ocs/v2.php/cloud/users/' + parameters.username, { method: 'DELETE', headers: validAdminAuthHeaders })```

artur
2021-10-16 10:31
I think the issue is the paramaters given to the state handler

artur
2021-10-16 10:33
in beta36 I got

artur
2021-10-16 10:35
in beta51 the fist parameter `setup` contains the password and the username

artur
2021-10-16 10:37
I must have missed a breaking change in https://github.com/pact-foundation/pact-js/commit/456567c83a5f155381eebb7dd3f6b60d3bc0060b ``` BREAKING CHANGE: the signature of state handlers has been updated to accept either a single function with parameters, or an object that can specify optional teardown and setup functions that run on the different state phases.```

tjones
2021-10-16 10:52
Ah, yes. The signature has changed. Maybe we can make the (re) migration path easier

tjones
2021-10-16 10:53
We could use `function.length` and assume the old format

jsoto128
2021-10-16 20:45
has joined #pact-js

fiszczu
2021-10-17 17:04
has joined #pact-js

brocheleau
2021-10-18 03:23
has joined #pact-js

andrerc
2021-10-18 22:11
has joined #pact-js

leonardo.viana
2021-10-18 22:54
Hi team. We?ve just upgraded from pact-js v3 beta.51 to beta.52 and we?re noticing one extra log line that seems a little concerning. Up to beta.51, the output of our consumer tests would be something like: ```10:59:15 [2021-10-18 17:59:14.487 +0000] INFO (766 on 43282697741d): pact-core@13.1.7: Publishing Pacts to Broker 10:59:15 [2021-10-18 17:59:14.491 +0000] INFO (766 on 43282697741d): pact-core@13.1.7: Publishing pacts to broker at: https://menloinfra.pactflow.io 10:59:18 PASS libs/api-client/src/lib/api/pact.spec.ts (10.383 s) 10:59:18 [2021-10-18 17:59:17.792 +0000] INFO (766 on 43282697741d): pact-core@13.1.7: 10:59:18 Tagged version 2.82.0-16-ge11add554 of menlo-frontend as "dev_lviana_pact" 10:59:18 Publishing menlo-frontend/pnr-policy pact to pact broker at https://menloinfra.pactflow.io 10:59:18 [33mA pact for this consumer version is already published. Overwriting. (Note: Overwriting pacts is not recommended as it can lead to race conditions. Best practice is to provide a unique consumer version number for each publication. For more information, see https://docs.pact.io/versioning)[0m 10:59:18 The latest version of this pact can be accessed at the following URL: 10:59:18 https://menloinfra.pactflow.io/pacts/provider/pnr-policy/consumer/menlo-frontend/latest``` However, on beta.52 there?s one extra line saying `ERROR (805 on 3af6c54f8b79): pact-core@13.2.0: Could not publish pact:` ```15:25:33 [2021-10-18 22:25:32.467 +0000] INFO (805 on 3af6c54f8b79): pact-core@13.2.0: Publishing Pacts to Broker 15:25:33 [2021-10-18 22:25:32.471 +0000] INFO (805 on 3af6c54f8b79): pact-core@13.2.0: Publishing pacts to broker at: https://menloinfra.pactflow.io 15:25:35 PASS libs/api-client/src/lib/api/pact.spec.ts (10.087 s) 15:25:36 [2021-10-18 22:25:35.122 +0000] ERROR (805 on 3af6c54f8b79): pact-core@13.2.0: Could not publish pact: 15:25:36 Created menlo-frontend version 2.83.0-dev-40-g6353f14a8 with tags dev_lviana_pact 15:25:36 [33m Next steps: 15:25:36 Configure the version branch to be the value of your repository branch.[0m 15:25:36 [32mPact successfully published for menlo-frontend version 2.83.0-dev-40-g6353f14a8 and provider pnr-policy.[0m 15:25:36 View the published pact at https://menloinfra.pactflow.io/pacts/provider/pnr-policy/consumer/menlo-frontend/version/2.83.0-dev-40-g6353f14a8 15:25:36 Events detected: contract_published (pact content is the same as previous version with tag dev_lviana_pact and no new tags were applied) 15:25:36 No enabled webhooks found for the detected events``` Despite the `ERROR`, the pact seems to be getting published just fine (as can be verified by the subsequent line: `Pact successfully published`?), so it really seems like a bogus message. Is this a known issue?

tjones
2021-10-18 22:55
Yes, it is. I'll release a version with a fix later today

tjones
2021-10-18 22:55
thanks for the report

leonardo.viana
2021-10-18 23:06
Thanks for confirming, @tjones!

matt.fellows
2021-10-19 03:15
Thanks for fixing Tim. Are you using the JS API Leonardo to publish? If possible, i?d switch to the CLI if you could. We?re trying to move away from the JS SDK that wraps all of this so that the CLI can move at more pace. We currently do some hacky things, which is the root cause of this problem

tjones
2021-10-19 06:20
Also the CLI is way nicer - you don't need any custom scripts, it's installed automatically, and you can just call it straight from a script in `package.json`. See the examples in the pact-js repo

rodolfo.valenzuela
2021-10-19 07:43
has joined #pact-js

kamilyrb
2021-10-19 22:31
has joined #pact-js

sadikshahidain
2021-10-20 01:12
Does anyone recall why pact-js-core stopped checking checksums for the Ruby standalone binaries? I see that there https://github.com/pact-foundation/pact-js-core/blob/d264f0b800209a171b320039e7fa3c2dd621606e/standalone/install.ts#L390 around this, but it seems to have been removed at some point in the past 2 years (FWIW https://grep.app/search?q=.%2Atar.gz.%2Achecksum.%2A&regexp=true&filter[repo.pattern][0]=pact-foundation, it just seems like JS might've been the last/only to do so and so I'm trying to figure out if I really need to do so as a consumer of the PHP library for security's sake)

matt.fellows
2021-10-20 01:15
We didn?t see any value in the security of it given that we download it in the same step, so any compromise would mean that the malicious actor could also modify the checksum. Outside of security, we couldn?t see the value in keeping it. If the file was corrupted, the zip file wouldn?t unpack anyway Also we now pack the file directly into the bundle (rather than download at runtime), which is probably why we don?t have the checksums anymore

sadikshahidain
2021-10-20 01:17
Awesome, ty for that context. And yeah I think in that case I'll see about checking against a hard-coded hash in our code then, assuming our security team still considers this a significant risk (I've heard mixed takes so far...), and just make some notes around managing upgrades for it.

tjones
2021-10-20 05:49
Which version are you asking about? The current main release checks the checksums, the current beta does not (because the binaries are bundled with the package, so we'd be marking our own exam)

tjones
2021-10-20 05:50
Note that the code you linked to is not a dependency of pact-js's current release. This is what the current release uses: https://github.com/pact-foundation/pact-js-core/blob/pact-node/standalone/install.ts


artur
2021-10-20 11:43
trying to update from beta 36 to beta 53 I get `Request Failed - One or more of the state change handlers has failed during teardown phase` To find out which teardown phase failed I removed all teardowns in the state handlers, still II get that message. How can I find out where its coming from?

artur
2021-10-20 11:58
oh noooo it's the timeout. I'm hunting that :ghost: since days. It has nothing to do with the handler, its the timeout

tjones
2021-10-20 14:34
Ah! Which timeout?

joel.whalen588
2021-10-20 20:27
has joined #pact-js

sadikshahidain
2021-10-21 01:58
Mmm, I see. And yeah I didn't have a specific version in mind, was just trying to understand if it would make sense for me to start an issue on the Pact-PHP repo to do the same (and then also try to make a PR for it). I'm still in conversation with our security team about it, but it doesn't feel like downloading the checksum for comparison to the downloaded standalone binary will make much of a difference to them at this stage. (I'm still trying to get clarity on whether the binaries being bundled with the package will make a difference to them security-wise)

matt.fellows
2021-10-21 02:14
Is the context as a user of the package? Are you assessing the security of our packages or for some other reason?

sadikshahidain
2021-10-21 02:15
Correct, as a user assessing security. This all started from someone pointing out that downloading a binary looked vaguely similar to how the CodeCov breach from earlier this year happened (fwiw I still don't fully understand what happened for that)

matt.fellows
2021-10-21 02:29
All the better reason to have the artifacts bundled into the package. You still need to put other zero trust mechanisms in place (which I?m sure you do!), but that will certainly reduce the # of flags being raised

sadikshahidain
2021-10-21 02:33
Yeah for sure. And lol idk about the "I'm sure you do" part though. Maybe "I sure hope you do" is more appropriate :sweat_smile: I'll definitely bring this context back to the security team though and see if we can't bring Pact back into the fold with maybe just tracking these concerns for now.

matt.fellows
2021-10-21 03:35
Alternatively, take a look at the v3 beta - it won?t have this problem and doesn?t need to embed Ruby or other stuff like that

artur
2021-10-21 06:21
the one that you set in the `Verifier` options I think it supposed to be the timeout for the state-handler. But it feels like accumulated for all state handlers.

matt.fellows
2021-10-21 06:23
Ah, the timeout is applied to all of the HTTP interactions from the core (Rust) to the outside world. So it will apply to the state handlers and also to the verification requests

matt.fellows
2021-10-21 06:24
Verbose logs _should_ show this, but knowing you Artur you would have tried that, so that tells me we may have a visibility problem

artur
2021-10-21 06:26
I can double check if I haven't looked detailed enough in the logs.

artur
2021-10-21 06:28
Is the timeout reset after every interaction / state handler or for all together? I cannot prove it yet but it looks to be that my tests are fine if I only run some of them but fail in the sum

matt.fellows
2021-10-21 06:30
see if you can bump that timeout for now

matt.fellows
2021-10-21 06:30
I can see that the timeout is used in a few places. For the rust _core_, the timeout is per request

matt.fellows
2021-10-21 06:31
but it looks like we?ve retained the timeout also at a higher level (i.e. for all verifications)


matt.fellows
2021-10-21 06:32
It?s 30s by default, but i?ve you?ve overridden that to something smaller that could be the cause

tjones
2021-10-21 06:50
To be clear, pact-js has never downloaded the checksum separately (it was bundled with the package). From the next major version (currently in beta), it bundles the binaries instead of the checksums. If you trust packages from npm, this is the same risk.

tjones
2021-10-21 06:53
I don't think the risk profile is any larger. Having an attacker compromise the binary is similar to compromising a dependency (which has happened before in npm, although not to pact-js).

tjones
2021-10-21 06:53
There's a good writeup of the CodeCov issue here - https://blog.gitguardian.com/codecov-supply-chain-breach/

artur
2021-10-21 06:57
I have a pact file with 185 interactions when I set the timeout to `30000` I get aound 101 failures increasing the timeout to `60000` only 79 I'm pretty sure no interaction or state handler takes 60sec by itself but the timeout corresponds to the overall runtime of the test. setting it to `30000` makes the verifier finish and fail after around 37 sec setting it to `60000` make the same set of tests fail after around 67 sec that makes me think its an overall timeout, or if its not supposed to be its not reset somewhere

artur
2021-10-21 06:58
also it cannot be set to more than `65535` https://github.com/pact-foundation/pact-js/issues/761

matt.fellows
2021-10-21 07:02
ah, I just read that and can see the issue

matt.fellows
2021-10-21 07:03
@tjones we have two timeouts that are being used for different purposes. We use the `timeout` value both as an overall verification timeout, and also a per-request timeout.

tjones
2021-10-21 07:04
We do. But the refusal to set it as higher than 65535 is the real problem

matt.fellows
2021-10-21 07:05
indeed

artur
2021-10-21 07:05
in the debug output I cannot see anything that indicates the timeout issue

artur
2021-10-21 07:06
this is the last output, it shows the request and response and it looks as expected to me#

tjones
2021-10-21 07:06
Yeah, I agree. This really highlights the need to do a full review of the rust logging

matt.fellows
2021-10-21 07:06
trace might have it

tjones
2021-10-21 07:06
It's saying that it can't connect to the state endpoint (the proxy in pact-js)

tjones
2021-10-21 07:07
`localhost` is suspicious. I think we should use an IP.

artur
2021-10-21 07:08
that is the other funny thing, after the crash it seems to forgotten the `providerBaseUrl`

artur
2021-10-21 07:08
`Request Failed - Invalid response: error sending request for url (http://localhost:38463/ocs/v1.php/apps/files_sharing/api/v1/shares/-1): error trying to connect: tcp connect error: Connection refused (os error 111)`

artur
2021-10-21 07:09
but I have definetely set the providerBaseUrl to `http://localhost/owncloud-core`

tjones
2021-10-21 07:10
Ah, so, pact-js lies to Rust about the providerBaseUrl

tjones
2021-10-21 07:10
because all requests go through a proxy

tjones
2021-10-21 07:11
(which is what `/_pactSetup` is hosted on)

artur
2021-10-21 07:12
and the proxy refuses the connection because it ran into a timeout


tjones
2021-10-21 07:12
it shouldn't.

tjones
2021-10-21 07:13
The timeout is unrelated to the proxy.

tjones
2021-10-21 07:16
I suspect the rust core is misreporting the error

tjones
2021-10-21 07:17
but it's hard to say for sure. I reckon we'll know more once we can fix the timeout issue

artur
2021-10-21 07:17
OK, that error message set me on a wrong path for debugging.

tjones
2021-10-21 07:17
Can you see the state change endpoint in the debug log?


tjones
2021-10-21 07:19
this file contains the logs that we're expecting

artur
2021-10-21 07:21
yes in the debug logs I see stuff like ```[2021-10-21 07:03:26.172 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: incoming request: {"body":{"action":"setup","params":{"password":"test123","username":"test123"},"state":"the user is recreated"},"headers":{"content-type":"application/json","accept":"*/*","host":"localhost:38463","content-length":"103"},"method":"POST","path":"/_pactSetup"} [2021-10-21 07:03:26.173 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state '{"action":"setup","params":{"password":"test123","username":"test123"},"state":"the user is recreated"}' [2021-10-21 07:03:26.173 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state 'the user is recreated' [2021-10-21 07:03:27.015 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: outgoing response: {"body":"{\"description\":\"user created\"}","headers":{"x-powered-by":"Express","content-type":"application/json; charset=utf-8","content-length":"30","etag":"W/\"1e-14HI00Phtn5NGrwCVZx+5BZjkfQ\""},"status":200} [2021-10-21 07:03:27.017 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: incoming request: {"headers":{"authorization":"Basic YWRtaW46YWRtaW4=","accept":"*/*","host":"localhost:38463"},"method":"GET","path":"/ocs/v1.php/cloud/users"} [2021-10-21 07:03:27.017 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: Proxying /ocs/v1.php/cloud/users [2021-10-21 07:03:27.251 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: outgoing response: {"body":"<?xml version=\"1.0\"?>\n<ocs>\n <meta>\n <status>ok</status>\n <statuscode>100</statuscode>\n <message/>\n </meta>\n <data>\n <users/>\n </data>\n</ocs>\n","headers":{"x-powered-by":"Express","date":"Thu, 21 Oct 2021 07:03:27 GMT","server":"Apache/2.4.46 (Ubuntu)","set-cookie":["ocuv4s8d5xsv=pq9fivhtej6736u6fhm51ekkor; path=/owncloud-core; HttpOnly; SameSite=Strict","oc_sessionPassphrase=pTH22542LqN9UmfyQ9N%2FKlC%2BGDTfCsYIvdcRjvkJrff%2Bk6bL01HqwuiyrFD1N%2FK37MvpV0og5uvWoqsj6PP6IrmBglPVspMM25O6uc5iEwGXowF2HJBrj%2F08x9cMJzpP; path=/owncloud-core; HttpOnly; SameSite=Strict","ocuv4s8d5xsv=p5dlregcibbjfjf5sjp0tae7i2; path=/owncloud-core; HttpOnly; SameSite=Strict","cookie_test=test; expires=Thu, 21-Oct-2021 08:03:27 GMT; Max-Age=3600","oc_username=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core; HttpOnly","oc_token=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core; HttpOnly","oc_remember_login=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core; HttpOnly","oc_username=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core/; HttpOnly","oc_token=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core/; HttpOnly","oc_remember_login=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core/; HttpOnly","ocuv4s8d5xsv=vth47qc2ls0mm09a5n16gmalep; path=/owncloud-core; HttpOnly; SameSite=Strict","ocuv4s8d5xsv=9024b41hio8lds8h5crr79s30l; path=/owncloud-core; HttpOnly; SameSite=Strict"],"expires":"Thu, 19 Nov 1981 08:52:00 GMT","cache-control":"no-store, no-cache, must-revalidate","pragma":"no-cache","content-security-policy":"default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src *; img-src * data: blob:; font-src 'self' data:; media-src *; connect-src *","x-xss-protection":"0","x-content-type-options":"nosniff","x-frame-options":"SAMEORIGIN","x-robots-tag":"none","x-download-options":"noopen","x-permitted-cross-domain-policies":"none","vary":"Accept-Encoding","content-length":"146","connection":"close","content-type":"text/xml; charset=UTF-8"},"status":200} [2021-10-21 07:03:27.254 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: incoming request: {"body":{"action":"teardown","params":{"password":"test123","username":"test123"},"state":"the user is recreated"},"headers":{"content-type":"application/json","accept":"*/*","host":"localhost:38463","content-length":"106"},"method":"POST","path":"/_pactSetup"} [2021-10-21 07:03:27.254 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state '{"action":"teardown","params":{"password":"test123","username":"test123"},"state":"the user is recreated"}'```

artur
2021-10-21 07:21
and that all looks correct to me

tjones
2021-10-21 07:22
I agree. I suspect the Rust core is not reporting the correct error (although it does seem strange)

artur
2021-10-21 07:24
the `setting up state` log comes twice. First with the JSON then with the name

artur
2021-10-21 07:25
```[2021-10-21 07:03:23.165 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state '{"action":"setup","params":{"password":"test123","username":"test123"},"state":"the user is recreated"}' [2021-10-21 07:03:23.165 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state 'the user is recreated'```

tjones
2021-10-21 07:26
Yeah, looks like the logs there have a few issues. Firstly, it says `Setting up state` when it should say `Received state change request`, and should probably be a trace log. Secondly, we don't log at all if we ignore the state change request because we don't have a handler.

tjones
2021-10-21 07:26
Well, we do, but only if there's absolutely no handler

tjones
2021-10-21 07:27
I think line 45 and 51 need else -> debug("Not tearing down state ${state}") (etc)

vasil.vasilev
2021-10-21 08:41
has joined #pact-js

ben.crinion
2021-10-21 11:09
has joined #pact-js

ben.crinion
2021-10-21 11:14
Hi, we're getting an error when trying to verify pacts for messages and for a rest contract with the same participant name. We've come across a fairly old github issue (https://github.com/pact-foundation/pact-js-core/issues/179). Is it still the case that we need different participant names for our message and rest pacts?

vince.lee
2021-10-21 11:17
hi folks we are in the process of building out our contract test suite with pact, and have run into an issue when we come to test a new message. :thread:

vince.lee
2021-10-21 11:18
we have a single `MessageProviderPact` test as follows, which works fine: ```// my-message-a.test.ts describe('my message A', () => { const p = new MessageProviderPact({ messageProviders: { 'part-ex-cancellation-completed event': () => Promise.resolve({ foo: 'bar' }), }, stateHandlers: { 'part-ex is removed from a delivered order': async () => { // setup some state return Promise.resolve(); }, 'part-ex is removed from a collected order': async () => { // setup some other state return Promise.resolve(); }, }, verbose: true, provider: 'my-provider', providerVersion: versionFromGitTag(), consumerVersionTags: ['local-stage'], providerVersionTags: [process.env.BRANCH_NAME, process.env.STAGE], enablePending: false, pactBrokerUrl: 'https://me.pactflow.io', pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: true, }); it('matches the contract', async () => { return await p.verify(); }); });```

vince.lee
2021-10-21 11:19
when we come to create a new test, for a different message, we copy this file and add it as a new one. however, when we run the contract tests in jest, the first test fails

vince.lee
2021-10-21 11:19
i got around this by adding both sets of stateHandlers and messageProviders into the single test file, but imagine this will become unwieldy and slow

vince.lee
2021-10-21 11:20
what's the best way to have multiple test files?

vince.lee
2021-10-21 11:29
we are using http://pactflow.io as the broker

matt.fellows
2021-10-21 11:49
What do you mean ?when we come to create a new test?? The short answer is, I think, at the moment I think, you can?t.

matt.fellows
2021-10-21 11:49
you could create separate providers that only test specific consumers though

matt.fellows
2021-10-21 11:49
i.e. use `consumerVersionSelectors` and use the consumer to split the tests apart

achuljyan
2021-10-21 19:20
Hello, It looks like pact Verifier doesn't have a parameter to write logs to a file (like Pact's "log" parameter). At least according to this doc: https://github.com/pact-foundation/pact-js#verification-options Why not have such option for Verifier?

estephania.calvo
2021-10-21 19:27
has joined #pact-js

ahmetbcakici
2021-10-21 22:38
has joined #pact-js

sadikshahidain
2021-10-22 01:41
Yeah that's the sort of case I made to our security team earlier today, that if/once the binary is bundled it's just like any other dependency. (haven't heard back yet though) Also I know this is the wrong channel but should I write up an issue for PHP to bundle the binary? I'm not sure what's involved but I'd be willing to tackle it myself, unless you all already had plans to do so or it requires more context than I'd be able to gain

matt.fellows
2021-10-22 01:51
that?d be great, thanks!

vince.lee
2021-10-22 08:24
> What do you mean ?when we come to create a new test?? when we want to test a different message published by the provider eg we have a 'part-ex-cancellation-completed' event as above, but we also publish 'part-ex-cancellation-failed' is it that we should just have a single test file, into which we load lots of different messageProviders to satisfy all of consumers?

matt.fellows
2021-10-22 08:49
yeah that?s right. You can still split the handlers etc. into separate files, but it does require a single entrypoint to configure what is verified

abarcadabra
2021-10-22 12:30
has joined #pact-js

harwin1494
2021-10-22 19:04
has joined #pact-js

anindita.ghosh
2021-10-22 23:26
has joined #pact-js

tjones
2021-10-24 12:52
Looks like this is an oversight - it is supported, but the option doesn't seem to be documented.

tjones
2021-10-24 12:54
`logDir` will tell it where the log directory should be

tjones
2021-10-24 12:54
You can also use `out` to tell it to write the output to a file instead of standard out.

tjones
2021-10-24 12:54
However, both of these options will be removed in the next version - what is the use case for wanting the logs to go to a file?

sadikshahidain
2021-10-25 04:32
Wrote up this issue - https://github.com/pact-foundation/pact-php/issues/227 As a next step for me I'll try to figure out/understand how Pact-JS is doing the bundling of the binary in the beta channel today, so if y'all have any quick pointers for that just lmk

matt.fellows
2021-10-25 04:35
Thanks!

tjones
2021-10-25 06:21
@sadikshahidain: https://github.com/pact-foundation/pact-js-core/blob/master/script/download-libs.sh ^ This downloads all the libraries (the Ruby binaries and the Rust FFI libraries). The first script mentioned there reads the versions that we're expecting out of our source code, and then exports them as environment variables.

tjones
2021-10-25 06:22
If you just want the download of the ruby standalone, this script (and the dependencies it names at the top) are all you need: https://github.com/pact-foundation/pact-js-core/blob/master/script/lib/download-standalone.sh

rajnish.maurya
2021-10-25 06:47
has joined #pact-js

alanbos
2021-10-25 10:11
has joined #pact-js

achuljyan
2021-10-25 12:24
It looks like https://github.com/pact-foundation/pact-js-core/issues/100 has been resolved : https://github.com/ruby/ruby/pull/4505 Is it possible to rebuild Pact with the latest Ruby version to get rid of the long path issue?

matt.fellows
2021-10-25 12:56
It's not that easy I'm afraid. We use traveling ruby which is major versions behind

matt.fellows
2021-10-25 12:57
I'd jump on the v3 beta or wait for that

achuljyan
2021-10-25 13:35
ok thank you @matt.fellows for the quick response

kuzmanovid
2021-10-25 13:59
has joined #pact-js

achuljyan
2021-10-25 14:05
btw when are you planning to release v3?

j.malyjasiak
2021-10-25 14:24
has joined #pact-js

rtbhosale17
2021-10-25 14:25
has joined #pact-js

stefano.mantini
2021-10-25 14:31
has joined #pact-js

r.muthukumar136
2021-10-25 14:59
has joined #pact-js

dimundo
2021-10-25 19:45
hi! if `"match": "type"` is declared in interaction in which cases it doesnt work and expects exact match, not type? could this be due to this ? ``` "metadata": { "pactSpecification": { "version": "2.0.0" } }```

dimundo
2021-10-25 19:46
consumer is pact-js v2 provider is pats4s ( aka jvm/scala )

gravis54
2021-10-25 21:46
has joined #pact-js

misha.antipenko
2021-10-25 21:57
has joined #pact-js

matt.fellows
2021-10-26 01:53
Soon, that's the best answer

matt.fellows
2021-10-26 01:54
We're currently blocked on an upstream issue with node FFI bindings

matt.fellows
2021-10-26 01:54
Aside from some minor API changes it's good to use IMO

matt.fellows
2021-10-26 01:55
Mmm that matcher should work

matt.fellows
2021-10-26 01:55
Any chance you could please share the pact and/or errors you're seeing Dmitry?

tjones
2021-10-26 03:05
How are you generating the matchers in your interaction?

dimundo
2021-10-26 05:40
``` it("should POST to resolve signal ", async() => { const path = POST_SIGNAL_RESOLVE_URL await provider.addInteraction({ state: "2. i will resolve signal", uponReceiving: "a request to resolve signal", withRequest: { method: "POST", path, headers: { "Content-Type": "application/json" }, body: { ...tableIdBody, signalId: string("ddd") }, }, willRespondWith: { status: 200 }, }) const res = await makePostRequest(provider.mockService.baseUrl + path, { ...tableIdBody, signalId: "signalguid" }) expect(res.status).toBe(200) expect(res.ok).toBeTruthy() await provider.verify() })```

dimundo
2021-10-26 05:40
```signalId: string("ddd")``` and ```signalId: like("ddd")``` makes same json

dimundo
2021-10-26 05:41
``` "body": { "tableId": "table1", "signalId": "ddd" }, "matchingRules": { "$.body.signalId": { "match": "type" } } },```

j.malyjasiak
2021-10-26 06:01
@j.malyjasiak has left the channel

matt.fellows
2021-10-26 06:44
hmm that looks fairly innocuous

tjones
2021-10-26 06:58
That looks right. It should match any string as `signalId`

dimundo
2021-10-26 07:00
looks like my brain was a bit melted - this works properly for consumer and provider tests were failing, because `ddd` wasnt something provider expects

matt.fellows
2021-10-26 07:02
:laughing:

matt.fellows
2021-10-26 07:02
you have plenty of credits in the bank Dmitry!

adomanski
2021-10-26 10:43
has joined #pact-js

kriegster108
2021-10-26 14:58
has joined #pact-js

jhopkinwilliams
2021-10-27 00:59
is it easy to set up pact with aws lambdas written in typescript? Also how would i. go about that?


matt.fellows
2021-10-27 01:13
Yes you can do it for sure

jhopkinwilliams
2021-10-27 01:17
Thanks Matt! Ill take a look at that. Is that a tutorial in that doco too?

matt.fellows
2021-10-27 01:23
I wouldn't call it a tutorial on AWS but yes there are tutorials there

tjones
2021-10-27 04:01
The answer is "yes, it's easy" and "how you set it up depends on whether your lambda is the provider or consumer, and if it is the provider (or a message consumer), how you are invoking it"

adam.witko
2021-10-27 07:36
has joined #pact-js

adam.witko
2021-10-27 07:42
Hey all :wave: I am looking to get on board with the recent migration to ?branch? stuff over in Pact. We use `@pact-foundation/pact` in our consumer/providers, which itself uses `@pact-foundation/pact-node` (renamed to pact-js-core). I have found https://github.com/pact-foundation/pact-js/issues/757 that looks to have no in progress or merged PR, so I?m thinking of picking it up. This looks to be a two part change to both the repos for `@pact_foundation_greet/pact-js-core` to expose and handler the new properties, then `@pact-foundation/pact` to use the updated pact-js-core package. Is anyone currently working on this, or am I good to get some PRs open? Cheers!

matt.fellows
2021-10-27 08:19
That'd be great! Not in front of my computer but there is probably already issues raised to do it

alex.macpherson
2021-10-27 08:28
has joined #pact-js

matt.fellows
2021-10-27 11:19
ah, you linked to the issue :laughing:

matt.fellows
2021-10-27 11:20
Just needs the new type added to pact-js-core, and then a version bump of that dependency in pact-js and it?s good to go

matt.fellows
2021-10-27 11:22
If you wanted to pick this related change up that would also be welcome: https://github.com/pact-foundation/pact-js/issues/750

adam.witko
2021-10-27 16:15
I?ll take a lookie. Do you, or anyone here, know if I need to contribute from forking then raising a PR to the pact-foundation/pact-js-core repo? It?s documented like this in the pact-js repo but not pact-js-core repo

yurich00
2021-10-27 18:10
has joined #pact-js

lincolnf
2021-10-27 23:30
has joined #pact-js

tjones
2021-10-28 01:47
Yes, that's right

tjones
2021-10-28 01:47
to get it into the main pact-js, we'll need to backport it to the `pact-node` branch in the pact-js-core repo

lawrencemajmacdonald
2021-10-28 07:33
has joined #pact-js

zsolt.vilagos
2021-10-28 10:00
has joined #pact-js

zsolt.vilagos
2021-10-28 10:01
@zsolt.vilagos has left the channel

norway.martin
2021-10-28 15:59
@norway.martin has left the channel

ramesh.dhanasekaran
2021-10-29 02:20
has joined #pact-js

matt.fellows
2021-10-29 05:16
:raised_hands:

matt.fellows
2021-10-29 05:16
Reminder to myself to manually compile / upload Arm artifacts for M1 users

matt.fellows
2021-10-29 05:16
I think the previous release version artifacts should work because we haven't changed the rust code

matt.fellows
2021-10-29 05:16
But I'll verify

harwin1494
2021-10-29 08:22
Hey all, I am getting this error while running the pact test at the consumer side. Correct me if I am wrong, but as per my understanding we can write consumer tests giving no relevance to what an actual provider will respond like, so if I am providing any status code to be validated in my test script, should I be getting this error? (The line here is from the actual micro-service js file).

matt.fellows
2021-10-29 08:25
What's the actual problem, we can't tell from that code

matt.fellows
2021-10-29 08:27
Please share your test code

harwin1494
2021-10-29 08:31
```d```

harwin1494
2021-10-29 08:31
I am unable to get a the exact code here, some problem with my ide.

christopher.mcewen
2021-10-29 12:14
has joined #pact-js

catalin.comarnescu
2021-10-29 12:31
has joined #pact-js

sushant.soni
2021-10-29 12:32
@catalin.comarnescu

catalin.comarnescu
2021-10-29 12:34
hi @uglyog, can we find more details about this change somewhere?

catalin.comarnescu
2021-10-29 12:34
seems lack of capture groups prevents us from using e.g. OR between terms

catalin.comarnescu
2021-10-29 12:35
``` "mismatches": [{ "attribute": "body", "description": "Expected 'look_bordered' to match 'look|look_bordered|slider_cta'", "identifier": "$.data.content.items.0.type" }],```

catalin.comarnescu
2021-10-29 12:35
tried with and without the brackets

catalin.comarnescu
2021-10-29 12:35
again, this was working fine (with the capture group) with pact-js v2

mui_ume
2021-10-29 12:52
Hi Matt, I clone from this git repo https://github.com/pactflow/example-consumer when I run npm start, I got this error × TypeError: Cannot read properties of undefined (reading ?endsWith?)

mui_ume
2021-10-29 13:10
I need to add the .env file and define REACT_APP_API_BASE_URL=http://localhost:3000 but I got ```Error: Request failed with status code 404```

kiran.rudrangi
2021-10-29 16:48
has joined #pact-js

matt.fellows
2021-10-29 21:34
It's not designed to be run without the backend. See the usage in the readme

matt.fellows
2021-10-29 21:34
It is designed to run tests though

uglyog
2021-10-30 00:53
Is that with Pact-JS or Pact-JVM. I did a quick test with Pact-JVM, and that regex works as exepected

matt.fellows
2021-10-30 02:04
Can you please share the versions of software producing the pact file and verifying it?

mui_ume
2021-10-30 02:36
are u referring to this part of the README.md ```To be able to run some of the commands locally, you will need to export the following environment variables into your shell: PACT_BROKER_TOKEN: a valid API token for Pactflow PACT_BROKER_BASE_URL: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io PACT_PROVIDER=pactflow-example-provider-dredd: this changes the default provider to the Dredd based provider (https://github.com/pactflow/example-provider-dredd) PACT_PROVIDER=pactflow-example-provider-postman: ... Postman (https://github.com/pactflow/example-provider-postman) PACT_PROVIDER=pactflow-example-provider-restassured: ... Rest Assured (https://github.com/pactflow/example-provider-restassured)```

mui_ume
2021-10-30 02:36
I follow the above and I did the next section make test, it give me the error ```TypeError: Cannot read property 'endsWith' of undefined 10 | url = process.env.REACT_APP_API_BASE_URL; 11 | } > 12 | if (url.endsWith("/")) { | ^ 13 | url = url.substr(0, url.length - 1) 14 | } 15 | this.url = url```


mui_ume
2021-10-30 02:43
I was following this youtube workshop, which part of it show the backend setup?

mui_ume
2021-10-30 03:37
sorry matt, it?s at 0:34, I got it work now

matt.fellows
2021-10-30 05:27
You don't run the provider at all as part of testing

matt.fellows
2021-10-30 05:28
There is a corresponding provider project you can run to see the application working

matt.fellows
2021-10-30 05:28
But for the purposes of contract testing you don't need to start the app

mui_ume
2021-10-30 05:39
I run npm start at the example-consumer, it start localhost:3000 with this error on the page ```Error: Request failed with status code 404```

matt.fellows
2021-10-30 05:54
For posterity, I was referring to the usage instructions: https://github.com/pactflow/example-consumer#usage

mui_ume
2021-10-30 05:57
got it work ! thanks I run npm start at the git repo example-provider-dredd

jhopkinwilliams
2021-11-01 01:35
Hey Matt, I set up 2 very basic APIs with serverless on AWS lambda. Basically 1 just returns some City data and the other request calls this function to receive the data. Im a bit lost on the documentation for this: https://docs.pactflow.io/docs/examples/aws/sns/consumer/readme/ and I am not too sure on how to get this set up for my organisation. Im not really a developer you see.

matt.fellows
2021-11-01 01:48
The one caller the other just uses a standard pact test, nothing AWS specific there

matt.fellows
2021-11-01 01:48
Assuming you have it behind AWS API Gateway, The way to think about the HTTP AWS one is this

matt.fellows
2021-11-01 01:49
If you can start the API locally (e.g. serverless local) it just looks like any other provider pact test and there is nothing AWS specific about it

matt.fellows
2021-11-01 02:20
make sense?

jhopkinwilliams
2021-11-01 03:00
sorry Matt, i wasnt at my desk just then

jhopkinwilliams
2021-11-01 03:01
what I normally do is ```sls deploy``` I havent tried to start serverless locally before

jhopkinwilliams
2021-11-01 03:03
do you have a link to a bare bones consumer test i can put in my repo?

matt.fellows
2021-11-01 06:13
All of those examples are a good starting point


saurabh.goel
2021-11-01 12:58
hi everyone, I am successfully able to inject values from provider for APIs https://docs.pact.io/implementation_guides/jvm/consumer/junit/#having-values-injected-from-provider-state-callbacks-3611. Is there something similar for message pacts? like I have a field in "contents" of my messagepact, which i would like to dynamically substitute by my provider state variable.

matt.fellows
2021-11-01 13:28
The state handlers are the same as for HTTP so yes you should

tjones
2021-11-01 14:36
However, pact-js does not yet support them. You can use the beta, which will bring you these features, but it's not stable.

saurabh.goel
2021-11-01 14:36
ohh, ok thanks timothy

saurabh.goel
2021-11-01 14:36
and matt

ahmed_syed
2021-11-01 20:46
has joined #pact-js

matt.fellows
2021-11-01 23:34
ah I did misread that. I thought you were already using the beta. Thanks for clarifying Tim

somayajulaas
2021-11-02 00:38
has joined #pact-js

john
2021-11-02 03:32
has joined #pact-js

harwin1494
2021-11-02 08:19
Hi, I am trying to use matcher in PACT-js but getting this error, do I need to run npm install again?

harwin1494
2021-11-02 08:48
Update :- I added `import { Matchers } from '@pact-foundation/pact';` and the above error got resolved. But now getting reference error. Please help.

matt.fellows
2021-11-02 08:51
somethingLike isn't a function

matt.fellows
2021-11-02 08:51
That's why it's failing

matt.fellows
2021-11-02 08:51
`like` is probably what you want

harwin1494
2021-11-02 08:52
even that is throwing the same error

harwin1494
2021-11-02 08:55
@matt.fellows

tjones
2021-11-02 08:58
You probably want `Matchers.like` - have a look in the examples to see how it is done there

catalin.comarnescu
2021-11-02 08:59
Pact file is produced by Pact JVM 4.0.10, verified using pact-js 10.0.0-beta.52

harwin1494
2021-11-02 09:01
I am going through examples here https://docs.pact.io/implementation_guides/javascript/readme#match-common-formats, but couldnt find `Matchers.like`. Can you point me to the right one?

catalin.comarnescu
2021-11-02 09:04
``` "$.data.content.items[*].type": { "matchers": [{ "match": "regex", "regex": "(look|look_bordered|slider_cta)" }], "combine": "AND" },```

catalin.comarnescu
2021-11-02 09:04
this is the generated matcher

harwin1494
2021-11-02 09:06
it worked, thanks Tim. But while searching the channel for matchers example, simply using like/somethingLike also worked, is it related to some updates?

matt.fellows
2021-11-02 09:26
Some people alias code etc

matt.fellows
2021-11-02 09:26
The examples in the pact JS repo all are correct, so they should be a starting point rather than random people's code

rochitsen
2021-11-02 10:49
has joined #pact-js

catalin.comarnescu
2021-11-02 12:12
or the variant without the brackets

catalin.comarnescu
2021-11-02 12:12
``` "$.data.content.items[*].type": { "matchers": [{ "match": "regex", "regex": "look|look_bordered|slider_cta" }], "combine": "AND" },```

catalin.comarnescu
2021-11-02 12:13
but of course this one wouldn?t work as it?s not a valid regex

matt.fellows
2021-11-02 12:31
It looks like a valid regex to me. What's not valid about it?

finta.pl
2021-11-02 14:43
has joined #pact-js

catalin.comarnescu
2021-11-02 16:07
hm actually you?re right. but again, both fail the same way, with or without the brackets

catalin.comarnescu
2021-11-02 16:08
```"mismatches": [{ "attribute": "body", "description": "Expected 'look_bordered' to match '(look|look_bordered|slider_cta)'", "identifier": "$.data.content.items.0.type" }],```

alessandro.borraccino
2021-11-02 17:04
has joined #pact-js

myao
2021-11-02 22:23
has joined #pact-js

matti.anusha
2021-11-03 02:58
has joined #pact-js

ozgurerisir
2021-11-03 10:29
has joined #pact-js

christian.kampka
2021-11-03 13:23
Is there a way to have a pact include cors requests in the API contracts? I know that I can set `cors: true` on the consumer side, wich tells the mock server to "tollerate" a pre-flight request, but it does not seem to be recorded as part of the contract.

matt.fellows
2021-11-03 20:32
If it needs to be in the contract you should put it in the contract

matt.fellows
2021-11-03 20:33
There's no one set of CORS headers, you should specify the ones you need

john
2021-11-04 04:07
any idea how to resolve this: PactBroker::Client::Hal::ErrorResponseReturned - Error making request to https://dfsfds.pactflow.io status=401 Unauthorized. Please see https://docs.pactflow.io/docs/login-help for more information.

john
2021-11-04 04:07
I went through the documentation but everything seemed ot be ok

matt.fellows
2021-11-04 04:08
Can you please share your config that's failing?

john
2021-11-04 04:09
Sorry Matt what do you mean config?

matt.fellows
2021-11-04 04:09
401 means what you think it means. Are you using the correct bearer token?

john
2021-11-04 04:10
i go to the pactflow website

john
2021-11-04 04:10
and click the cog setting and get the read/write tokens

john
2021-11-04 04:11
i then dump them in a .env file

matt.fellows
2021-11-04 04:11
Thata the one!

john
2021-11-04 04:11
you want me to share the tokens with you?

matt.fellows
2021-11-04 04:11
Nah that's fine

john
2021-11-04 04:12
so all i do is click "Copy env vars" and paste it into my .env file

matt.fellows
2021-11-04 04:12
Are you sure it's the correct env car?

john
2021-11-04 04:12
the test:consiumer works

matt.fellows
2021-11-04 04:12
var*

john
2021-11-04 04:12
just not the publishing

matt.fellows
2021-11-04 04:13
Consumer doesn't need the token to run tests

matt.fellows
2021-11-04 04:13
What env var is it?

john
2021-11-04 04:14
i only have 2 env set the base url and the token

john
2021-11-04 04:15
PACT_BROKER_BASE_URL and PACT_BROKER_TOKEN

matt.fellows
2021-11-04 04:15
How does npx know about your .env file?

john
2021-11-04 04:16
good point

john
2021-11-04 04:17
where would i put that

john
2021-11-04 04:17
i put require('dotenv').config()

john
2021-11-04 04:17
in my consumerpact test

matt.fellows
2021-11-04 04:20
You put it in the environment directly or wrap it in a shell script.

matt.fellows
2021-11-04 04:21
It's usually only used in CI (publishing that is)

john
2021-11-04 04:51
ok no worries I will try that

uladzislau_danilchyk
2021-11-04 10:04
Hi all! Please, help me with checking specified array item. The problem is that array items can vary. And I need to check all of possible items structure in array. How to do that?

matt.fellows
2021-11-04 10:14
The new beta has an `arrayContaining` matcher that can do this: https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0#using-the-v3-matching-rules

john
2021-11-04 23:47
thanks that worked!

john
2021-11-05 02:40
just a quick question. I really enjoyed the Katacode tutorial for a basic pact consumer / providers scenario. Do you have something similar for something that uses aws lambdas and uses SQS? I know there is a work shop on that which uses SNS, im going to work through shortly. Another question what is the use of "can i deploy" if you have pact tests and you run them and they fail - you should not deploy then right?

tjones
2021-11-05 02:41
What Katacode tutorial?


tjones
2021-11-05 02:41
Oh right. That's a pactflow tutorial, and no, we don't have anything like that

john
2021-11-05 02:42
appologies dev isnt my strong point

tjones
2021-11-05 02:42
So, can-i-deploy is used to check version compatibility

john
2021-11-05 02:42
but my collegue was say the lambda uses an event bridge

tjones
2021-11-05 02:42
The pact tests are only one half of the equation

tjones
2021-11-05 02:43
Your pact tests say "I am confirming I can send these requests and understand these responses", and they generate a pact file

tjones
2021-11-05 02:43
that pact file can then be shared with the broker so that it can be verified by the provider

john
2021-11-05 02:43
my collegue send that the lamdas they hit arent like endpoints

tjones
2021-11-05 02:43
pact verification says "I am confirming I can understand these requests and generate these responses"

tjones
2021-11-05 02:44
can-i-deploy is used to see if the verification has run successfully with the versions in whatever environment you are deploying to.

tjones
2021-11-05 02:45
"ok, my pact tests pass, and I generated the contract (pact file). Now, is that contract implemented by my provider in the environment I want to deploy to?"

john
2021-11-05 02:45
when you say version. what do you mean? Do you mean version of the libaries your using?

tjones
2021-11-05 02:45
^ That's the question that can-i-deploy asks

tjones
2021-11-05 02:45
no, I mean version of the software that you're testing

john
2021-11-05 02:45
ah ok i see

john
2021-11-05 02:46
if i want to get up and running with the lambdas the best place for that would be that sns workshop?

tjones
2021-11-05 02:47
we don't have an sns workshop, as far as I am aware

tjones
2021-11-05 02:47
we have examples, though


john
2021-11-05 02:49
so that example should work with lambdas on aws right?

tjones
2021-11-05 02:50
Yes. (from memory I think that might even be what's tested there).

tjones
2021-11-05 02:50
However, there's a subtlety in that message pacts only check the content - they don't send and receive the messages like the http pacts do

tjones
2021-11-05 02:51
We're working on pact plugins that will enable the testing of actually sending and receiving messages

tjones
2021-11-05 02:51
Testing the content is still valuable, since that's the part that usually drifts

john
2021-11-05 02:52
is that pactflow?

john
2021-11-05 02:52
is pactflow and pact the same thing? Sorry if i seem confused

tjones
2021-11-05 02:54
No. Pactflow is a hosted broker (with extra features that work well for enterprise users, such as federated login and support for things like running verification backwards from OpenAPI specs)

tjones
2021-11-05 02:54
Pact is the open source project

tjones
2021-11-05 02:54
Pactflow happens to be run by many of the pact core maintainers, but the open source project has been around longer.

john
2021-11-05 02:54
how do you share the pacts with open source project?

tjones
2021-11-05 02:54
With the broker

john
2021-11-05 02:55
all the examples ive done so far was with that pactflow

tjones
2021-11-05 02:55
There's a docker image. If you don't want to set up your own broker, then Pactflow is a very easy option.

tjones
2021-11-05 02:55
That's because you're doing pactflow examples, it sounds like.

tjones
2021-11-05 02:55
The technology is the same.

tjones
2021-11-05 02:55
(except pactflow has more enterprise features)

tjones
2021-11-05 02:56
I'm not familiar with the pactflow examples because I don't maintain them

john
2021-11-05 02:56
all i need to do is to have a basic template for my development teams to be able to start using contract testing throughout the organisation. They mainly use aws lambdas

tjones
2021-11-05 02:56
Right. I would start with the example I sent you

john
2021-11-05 02:57
ok great, does that example use the broker?

tjones
2021-11-05 02:57
yes, all the examples do


john
2021-11-05 02:57
so just clone that and run it right?

tjones
2021-11-05 02:57
(in pact JS, our test broker is very kindly provided by pactflow)


tjones
2021-11-05 02:58
but, any code that speaks to the pactflow broker will also speak to the OSS broker

john
2021-11-05 02:58
ok i see great. thanks so much Timothy, im probably the least qualified person to be setting this up as i dont know anything about contract testing lol

john
2021-11-05 02:58
OSS is the open source broker right?


tjones
2021-11-05 02:59
yes, sorry. OSS as in "Open Source Software"

john
2021-11-05 02:59
ok ill clone that and let you know how i. get on thanks for your help


john
2021-11-05 03:35
hey Timothy

john
2021-11-05 03:36
I just cloned the repo and got the consumer running but im getting an issue with th e publishing. I didnt see in the example readme if i need any specific export env . I have some set up already for pactflow though

john
2021-11-05 03:38
i see that the package.json has this: ```--broker-base-url=https://test.pact.dius.com.au"```

john
2021-11-05 03:45
ok I got it working with using pactflow. @tjones if i want to use this without pactflow what credentials would i have to use etc?

tjones
2021-11-05 03:46
You would have to set up your own broker in your own infrastructure, and use the credentials you set up

tjones
2021-11-05 03:47
In my view it is much easier to use pactflow, which I can safely say because I don?t work for them

john
2021-11-05 03:48
ok i think for my need just have a working demo is valuable for the time being,

john
2021-11-05 03:48
thanks for all your help.

abubics
2021-11-05 06:21
:taco: for @tjones :tada:

dean.miley1
2021-11-05 11:40
has joined #pact-js

martha.nolan
2021-11-05 11:50
has joined #pact-js

martha.nolan
2021-11-05 12:14
Hi all, I'm currently trying to test a GraphQL request that uses `GET`, not `POST` . I've discovered that the `GraphQLInteraction` wrapper automatically adds the query to the request body & using a normal interaction causes the query to be parsed incorrectly. Is there a suggested way around this? Thanks!

matt.fellows
2021-11-05 12:16
If you look at that wrapper it's pretty basic

matt.fellows
2021-11-05 12:17
You might be able to overload the method (I'm on mobile so hard to check), or you could just steal it for your own purposes and modify it to work

matt.fellows
2021-11-05 12:18
A PR to allow the method to override would be good, but how does it work over GET if it sends a body? That's unusual

martha.nolan
2021-11-05 12:22
ah sorry, the request doesn't send a body - that's exactly the problem with using the current `GraphQLInteraction` - it seems to only account for `POST` requests.

matt.fellows
2021-11-05 12:22
Right, it's packed in a query string

matt.fellows
2021-11-05 12:22
I think you'll need to write your own wrapper

matt.fellows
2021-11-05 12:23
It should be easy enough to do, all graphql is is an abstraction on HTTP which Pact can handle.

matt.fellows
2021-11-05 12:26
If you get that working locally we can update Pact JS with the learnings if you're happy to share

matt.fellows
2021-11-05 12:26
I'm off for the night, but happy to support you in this thread

martha.nolan
2021-11-05 12:35
Ok, thanks for your help @matt.fellows

eniko_kollar
2021-11-05 16:46
has joined #pact-js

ashwin
2021-11-05 17:58
has joined #pact-js

d.philipp
2021-11-08 03:51
has joined #pact-js

romuald.quantin
2021-11-08 09:56
Hi @matt.fellows Thanks for the support, @martha.nolan is preparing a PR, that sounds like the best approach

romuald.quantin
2021-11-08 09:58
I'm still surprise we cannot do that with pact-js yet Either we are missing something, or devs don't use pact with graphql, or devs don't cache things, or they approach caching differently (must read: https://www.apollographql.com/blog/backend/caching/graphql-caching-the-elephant-in-the-room/) Any insights @matt.fellows? I want to make sure we are not missing a point, as our graphql endpoint will have http caching (which forces us to use `GET`)

matt.fellows
2021-11-08 09:59
I?ve never seen the request

matt.fellows
2021-11-08 09:59
it?s possible that people are doing it and have just wrapped it themselves

matt.fellows
2021-11-08 10:00
I also suspect a lot of people don?t use GraphQL very efficiently :stuck_out_tongue:

matt.fellows
2021-11-08 10:00
(I remember when I last did GraphQL that caching was an issue, i?m not sure if the `GET` based approach was an option then ~2016/2017)

romuald.quantin
2021-11-08 10:45
right, thanks for that :wink:

matt.fellows
2021-11-08 11:02
Also an opinion, but we often get people saying ?We don?t need to use Pact because GraphQL is type safe?

matt.fellows
2021-11-08 11:03
You can replace GraphQL with protobufs/OpenAPI/? and the story is the same

matt.fellows
2021-11-08 11:04
see also https://pactflow.io/blog/the-case-for-contract-testing-protobufs-grpc-avro/. The focus is protobufs, but problems 1-3 are usually the same

hamzah.saleem
2021-11-08 11:22
has joined #pact-js

srividya.ece
2021-11-08 12:17
has joined #pact-js

markus.joschko
2021-11-08 13:13
has joined #pact-js

matias.waterloo
2021-11-08 13:36
Hi! We upgraded pact-js and jest-pact to 9.16.5 and 0.9.1 and we are seeing a strange behaviour: the tests fail every time for a team mate but run fine for the rest of the developers. AFAIK we are using same config. Any ideas? ```thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 23 | } from '../mocks/pact/payments-fixtures'; 24 | > 25 | pactWith( | ^ 26 | { 27 | consumer: 'bff', 28 | provider: 'paymentsService', at setupProvider (node_modules/jest-pact/dist/pactWith.js:9:5) at node_modules/jest-pact/dist/pactWith.js:22:15 at node_modules/jest-pact/dist/internal/withTimeout.js:25:9 at Object.<anonymous>.exports.withTimeout (node_modules/jest-pact/dist/internal/withTimeout.js:5:5) at pactWithWrapper (node_modules/jest-pact/dist/pactWith.js:21:19) at node_modules/jest-pact/dist/internal/scaffold.js:7:69 at Object.pactWith (node_modules/jest-pact/dist/internal/scaffold.js:7:12) at Object.<anonymous> (src/__tests__/datasources/payments.test.ts:25:1)```

akke.luukkonen
2021-11-08 13:38
Coworker laptop just a bit too slow? We have this in our tests: ```// Jest timeout includes before/after hooks in addition to the tests themselves. // Sometimes cold starting Pact mock server takes a while, so default timeout of // 5 seconds is always not enough and may result in random failures on some machines. jest.setTimeout(15 * 1000);```

matt.fellows
2021-11-08 13:46
Seems plausible

matias.waterloo
2021-11-08 13:53
it worked!! thanks!

akanksha.sharma
2021-11-08 14:12
Hi All, I need to start Kafka consumer driven contract testing, can anyone suggest how to start it with Pactflow or can anyone share any documents or github link for the same.

belugin.v
2021-11-08 17:16
has joined #pact-js

matt.fellows
2021-11-08 22:01
We have a few examples here: https://docs.pactflow.io/docs/examples/

john
2021-11-09 01:48
just a question on teh Explanation for the message pact example. In the read me for the provider it says : We configure Pact to stand-in for the queue. The most important bit here is the `handlers` block but i dont see a handlers block in the example under number 2

matt.fellows
2021-11-09 03:25
Where are you reading sorry John?


tjones
2021-11-09 04:05
@matt.fellows - I think that's in the Go readme: https://docs.pact.io/implementation_guides/go/readme/#provider-producer - and it does look like that example might be missing the handlers block (from a skim read)

matt.fellows
2021-11-09 04:20
thanks, this is the JS channel so that would be confusing

matt.fellows
2021-11-09 04:20
but indeed, it?s missing that context


will.griffiths
2021-11-09 05:25
has joined #pact-js

john
2021-11-09 05:52
sorry I didnt see this thread, but I was refering to this: https://github.com/pact-foundation/pact-js/tree/master/examples/messages

john
2021-11-09 05:53
also it took me a while to figure out that: "All handlers to be tested must be of the shape `(m: Message) => Promise<any>` - that is, they must accept a `Message` and return a `Promise`." refered tot he syncronousBodyHandler.

matt.fellows
2021-11-09 05:53
yes, I can see why that would be confusing

matt.fellows
2021-11-09 05:54
that?s the consumer side

matt.fellows
2021-11-09 05:54
the provider side have `messageProviders` . Probably those docs got a little out of sync with reality

john
2021-11-09 05:56
Sorry for the random question but do you have any plans to implement all this for rust?

john
2021-11-09 05:57
like for example if we have a front end with react or something but your server is written in rust


matt.fellows
2021-11-09 05:59
There is the CLI and technically there are methods to call it I think. Probably best asking in #pact-rust

john
2021-11-09 06:00
tere is a pact-rust channel i dont see that let me check it out , thanks thats cool

navilooz
2021-11-09 08:48
has joined #pact-js

yousafn
2021-11-09 10:55
This topic has just come up at our work as a client is using graphql with a get request. So interested to see how you get on, or share any learnings

matt.fellows
2021-11-09 10:59
everyone comes out of the woodwork now :wink:

keith.hirst
2021-11-09 12:13
has joined #pact-js

martha.nolan
2021-11-09 12:19
Will keep you posted!

matt.fellows
2021-11-09 12:32
that?d be ace, thanks!

rbo
2021-11-09 17:47
has joined #pact-js

harshaan.n.khan
2021-11-10 05:38
has joined #pact-js

akanksha.sharma
2021-11-10 11:52
Thanks Matt for the documents. Can you please share me a guide like katacoda for Kafka as well in which a sequence is mentioned for consumer and provider tests. In the above examples there are a lot of files, not sure from where it is starting. Also, can you please let me know the commands to run the tests?

matt.fellows
2021-11-10 12:53
we don?t have a katacoda for Kafka I?m afraid (but assuming you?ve used the others and they were helpful?)

matt.fellows
2021-11-10 12:54
the commands are `make test` to run the tests locally

matt.fellows
2021-11-10 12:54
if you have your Pactflow environment variables available, you can emulate a CI build with `make fake_ci`

matt.fellows
2021-11-10 12:55
I?m not sure why, but we should have https://docs.pactflow.io/docs/examples/js/consumer/readme#pre-requisites on running them on that project also, i?ll fix that tomorrow

akanksha.sharma
2021-11-10 12:59
I can see node kafka consumer in example, I cannot see node Kafka producer, do we have that ?

akanksha.sharma
2021-11-10 13:01
and yes, I used Katacoda for contract test for product Api and it was very helpful and easy to understand. That's why I was looking for katacoda for Kafka as well

matt.fellows
2021-11-10 13:02
> I can see node kafka consumer in example, I cannot see node Kafka producer, do we have that ? No, just a java one. But the principles are all the same


matt.fellows
2021-11-10 13:03
SNS/Kafka/? it?s all the same.

akanksha.sharma
2021-11-10 13:04
Okay, let me take a look. Also, is there any possibility that we have katacoda for Kafka as well in near future:slightly_smiling_face:

matt.fellows
2021-11-10 13:05
i?ll add it to the list, but it?s a long list I?m afraid!

akanksha.sharma
2021-11-10 14:26
Okay, Thanks for adding :slightly_smiling_face:

esparga
2021-11-10 14:32
has joined #pact-js

esparga
2021-11-10 14:33
:wave: I?m here! What?d I miss?

martha.nolan
2021-11-10 14:35
Hi @matt.fellows, I've forked the repo and have made a change locally but am having trouble linking to my local version of pact-js to test my changes. Every time i try to link to it, the `node_modules` for `@pact-foundation` become empty. I've run `npm i` & `npm run dist` beforehand. Just wondering if I'm missing a setup step somewhere?

esparga
2021-11-10 14:37
So, i was trying to install pac-foundation to test it and I?m getting this error

esparga
2021-11-10 14:38
Error while installing binary: Checksum reject for file ?pact-1.88.77-win32.zip?

esparga
2021-11-10 14:39
has anyone get a clue how to solve this?

esparga
2021-11-10 14:46
is there a problem if im trying to use pact-1.88.77-win32.zip in a win64 machine?

tjones
2021-11-10 14:55
No, that should work. The error is saying that the checksum failed, so it's not downloading the binary correctly. Are you behind a corporate firewall or proxy? Sometimes there's a login screen that gets downloaded instead

esparga
2021-11-10 14:56
hmm..yes i am? but since the msg is saying? Finished downloading binary to c:? i assumed it download it all

tjones
2021-11-10 14:57
https://www.npmjs.com/package/@pact-foundation/pact-node ^ Have a look at `Pact Download Location` in this documentation

esparga
2021-11-10 14:57
ok thanks?gonna try to override the proxy..

tjones
2021-11-10 14:58
I suspect it has successfully downloaded something that isn't the binary zip. You can have a look at the file referenced in that error message to see

tjones
2021-11-10 14:59
(since you asked, the only windows issues currently are an issue with long paths that is hard to avoid because it's not fixed in Ruby, which is what the pact core binaries used by the current release are written in)

tjones
2021-11-10 15:00
We should improve that error message. The most common cause of the checksum failing is a corporate proxy.

esparga
2021-11-10 15:10
ok @tjones that worked like a charm?..using the ```{ "name": "some-project", ... "config": { "pact_binary_location": "/home/some-user/Downloads" }, ... }```

esparga
2021-11-10 15:11
BUT?. im getting a problem downloading version 1.88.77

esparga
2021-11-10 15:11
im able to download 1.88.79 but not the 77

esparga
2021-11-10 15:12
and every time i try to npm install ?it tries to find the version 1.88.77 in my machine?

esparga
2021-11-10 15:12
where the hell is it defined to get the 1.88.77 instead of the latest?

esparga
2021-11-10 15:14
btw. the command im using to install is : npm i --save-dev @ pact_foundation/pact@latest

esparga
2021-11-10 15:17
ok forget it!! it worked now?maybe a proxy issue

esparga
2021-11-10 15:17
thanks @tjones

tjones
2021-11-10 15:56
The version has to match the one it's expecting

tjones
2021-11-10 15:56
(so we know it passes all the tests)

tjones
2021-11-10 16:06
note that the version of `pact-foundation/pact` is different to the version of the standalone binaries

thales.areis
2021-11-10 19:33
has joined #pact-js

matt.fellows
2021-11-11 06:38
I think you need to link from the `dist` directory of Pact JS

matt.fellows
2021-11-11 06:42
You could probably get away with a relative import for the pact dependency in your `package.json` rather than `npm link` anyway

john
2021-11-11 07:56
hey all so im testing out the graphql example but i get this error: ```? ERROR: Error: Cannot find module 'source-map-support/register'```

matt.fellows
2021-11-11 08:39
We run it as part of our CI so I'd just double check what we execute and follow that

matt.fellows
2021-11-11 08:39
What are you doing when you get that error? Is there any other detail you can share?

henk.koopman
2021-11-11 08:56
has joined #pact-js

lena.lindblad
2021-11-11 09:58
has joined #pact-js

martha.nolan
2021-11-11 10:03
Thanks! Couldn't get it working with link, but got it working with relative import to `dist` folder.

matt.fellows
2021-11-11 10:33
It should be possible, but it?s been a little since I?ve tried

john
2021-11-11 10:46
i. install teh dependencies

john
2021-11-11 10:46
and i run the npm run test:consumer

matt.fellows
2021-11-11 11:41
Just ran fine for me on node 12.

matt.fellows
2021-11-11 11:41
have you tried cleaning node_modules and re running?

matt.fellows
2021-11-11 11:42
e.g. `npm ci` and then `npm run test:consumer`?

matt.fellows
2021-11-11 11:42
We run CI on 12,14 and 16

john
2021-11-11 11:49
ill giver it a go

martha.nolan
2021-11-11 15:03
Hi @matt.fellows, another question for you! I'm testing my change locally & essentially checking if the request method is `GET` & adding the query to the `RequestOptions` if it is, instead of adding it to the request body. The GraphQL query I'm passing is url encoded and I'm having trouble with the matching of this as it seems like Pact is performing some formatting of the query somewhere along the way. I can't find where this is happening (if it is at all!) in the codebase - could you point me in the right direction?

danieljak
2021-11-11 15:24
Hey :wave: I have a provider that has both message pacts (async) & both regular http pacts (GraphQL) When I setup the `MessageProviderPact` and run its verify - in addition to verifying the message pacts it also tries to verify the http pacts - which fails because I cannot configure it to run against the provider server (providerBaseUrl is not part of its types) Is there a special setup to verify a provider that has both async and sync pacts? :thinking_face:

radekkoubsky
2021-11-11 16:24
has joined #pact-js

aditya
2021-11-11 17:20
has joined #pact-js

claire
2021-11-11 17:55
has joined #pact-js

matt.fellows
2021-11-11 20:40
You actually need to give the provider different names at the moment - one for Async another for graphql

matt.fellows
2021-11-11 20:41
In the v4 pact spec you can have both in the same pact file

matt.fellows
2021-11-11 20:41
I think somebody did manage to work around it with consumer version selectors

matt.fellows
2021-11-11 20:45
Is it the matching error happening on the consumer side or provider?

matt.fellows
2021-11-11 20:47
I'll take a look today if I can

martha.nolan
2021-11-12 07:49
Consumer side, thanks!

gentritmm
2021-11-12 08:35
has joined #pact-js

matt.fellows
2021-11-12 09:44
how are you passing it in?

matt.fellows
2021-11-12 09:45
you could probably check the `pact.log` to see what it?s expecting, and also `mockService.ts` is where the interaction is registered with the underlying mock service

matt.fellows
2021-11-12 09:45
You can pass in either a full URL encoded string or a structured key/value object (where each key can have a URL encoded value)

wilson.espina
2021-11-12 09:52
has joined #pact-js

martha.nolan
2021-11-12 10:04
Thanks @matt.fellows, I'm passing the graph QL query as a URL encoded string - but the expected value adds two square brackets to the query meaning it doesn't match the actual value, so I'm wondering if Pact is performing some encoding of it's own

matt.fellows
2021-11-12 10:05
hmm

matt.fellows
2021-11-12 10:05
what does the log file say?

matt.fellows
2021-11-12 10:05
also, what does the URL encoded string look like?

martha.nolan
2021-11-12 10:16
Here is the diff - the one on the left (with extra bracket) is the 'expected value'. Other one is the actual. https://www.diffchecker.com/HFpO1jdA

matt.fellows
2021-11-12 10:18
can you please share the pact.log for it?

martha.nolan
2021-11-12 10:18
(That's what I get in the log)

matt.fellows
2021-11-12 10:19
there?s nothing else in the log?

martha.nolan
2021-11-12 10:20
Yes, sorry I sent that before you asked, one mo.

harwin1494
2021-11-12 10:54
Hi, I am facing a similar issue as explained here https://stackoverflow.com/questions/61748582/pact-dependency-stopping-tests-being-run. Has it been resolved ?

matt.fellows
2021-11-12 11:08
what version are you on?

matt.fellows
2021-11-12 11:09
have you upgraded to the latest?


matt.fellows
2021-11-12 11:09
looks unrelated to pact

harwin1494
2021-11-12 11:12
we are using the latest 9.16.5

matt.fellows
2021-11-12 11:13
hmm that still isn?t the full log, it?s missing the bit where it says ?registered interactions?

matt.fellows
2021-11-12 11:14
I?d like to see the full chain from start to finish

matt.fellows
2021-11-12 11:14
thanks

matt.fellows
2021-11-12 11:14
are you using Jest?

matt.fellows
2021-11-12 11:14
have you tried looking at your jest configs? The issue above turned out to be scanning/transforming packages it shouldn?t

harwin1494
2021-11-12 11:15
yes, ```"jest": "27.3.1", "jest-pact": "0.9.1",```

harwin1494
2021-11-12 11:15
what exactly to check in the jest configs?

matt.fellows
2021-11-12 11:15
:man-shrugging:

matt.fellows
2021-11-12 11:16
that was the issue above, so I?d just be creating a minimal example jest config that lets you run the jest test until it starts failing, and then you?ll know

harwin1494
2021-11-12 11:17
ok, will check

matt.fellows
2021-11-12 11:17
take a look at the above issue to start with, that might give you hint

martha.nolan
2021-11-12 11:19
Here's the full log :slightly_smiling_face:

harwin1494
2021-11-12 11:21
can we add something else in the jest config to resolve this, apart from upgrading the popsicle version (as explained in the above issue) ?

matt.fellows
2021-11-12 11:23
the takeaway of the above issue is it was a jest config issue, not a pact issue

matt.fellows
2021-11-12 11:24
so i?d start with a minimal jest config and see if that still causes the problem

matt.fellows
2021-11-12 11:28
I might be missing something, but this line: ```I, [2021-11-12T10:50:37.841280 #4019] INFO -- : Registered expected interaction GET /discovery?%7B%20collections(filter:%20%7Bid:%20%22234JK342LTdfr8%22%7D)%20%7B%20id%20title%20subsequentJourney%20%7B%20name%20label%20destinationUrl(platform:%20DOTCOM)%20%7D%20items(filter:%20%7Bavailable:%20%22NOW%22%20features:%20%5BMPEG_DASH%20CLEARKEY%20OUTBAND_WEBVTT%20HLS%20AES%20PLAYREADY%20WIDEVINE%20FAIRPLAY%5D%20broadcaster:%20ITV%20platform:%20DOTCOM%7D)%20%7B%20itemType%20...%20on%20TitleCollectionItem%20%7B%20titleItem%20%7B%20...%20on%20Special%20%7B%20categories%20title%20%7D%20...%20on%20Film%20%7B%20categories%20title%20%7D%20...%20on%20Episode%20%7B%20brand%20%7B%20categories%20title%20%7D%20%7D%20...%20on%20Title%20%7B%20titleType%20imageUrl%20legacyId%20brandLegacyId%20brand%20%7B%20title%20legacyId%20categories%20%7D%20synopses%20%7B%20ninety%20%7D%20broadcastDateTime%20channel%20%7B%20name%20%7D%20availableNow%20%7D%20availableNow%20%7D%20%7D%20...%20on%20BrandCollectionItem%20%7B%20brandItem%20%7B%20title%20synopses%20%7B%20ninety%20%7D%20legacyId%20categories%20latestAvailableTitle%20%7B%20imageUrl%20broadcastDateTime%20channel%20%7B%20name%20%7D%20availableNow%20%7D%20%7D%20%7D%20%7D%20%7D%20%7D``` shouldn?t that be ?Registered expected interaction GET /discovery?*query=*?.? ?

matt.fellows
2021-11-12 11:29
how are you passing in the query to your code, and the code to the framework?

matt.fellows
2021-11-12 11:29
I can see the extra `[` `]` though

martha.nolan
2021-11-12 11:52
:woman-facepalming: I think that was the issue - I assumed Pact would add `query=` so wasn't passing it myself.

martha.nolan
2021-11-12 11:59
Thanks for looking @matt.fellows - gonna double check, but now the query matching issue is no longer an issue I think we can just use a normal interaction - no need to update the `GraphQLInteraction` .

matt.fellows
2021-11-12 12:02
:laughing:

matt.fellows
2021-11-12 12:02
haha no worries

matt.fellows
2021-11-12 12:03
probably confusing because `query` is the same thing used for a query string!

matt.fellows
2021-11-12 12:03
glad it was something simple!

matt.fellows
2021-11-12 12:03
If it works, we can perhaps add another example that uses this way so others have a reference

matt.fellows
2021-11-12 12:04
it might still be nice to have a specific class/type, to make it more convient / readible. Not sure, let me know what you think anyway

harwin1494
2021-11-12 12:12
can you suggest any sample config, because I am unable to resolve the error inspite of making several changes in "`testPathIgnorePatterns`"?

akanksha.sharma
2021-11-12 13:44
Hi Matt, just to understand one thing, as in contract testing we have consumer test and producer test in the same framework but we have two different frameworks for kafka consumer and producer. Its kind of hard to understand to know the sequence of files in these. Can you please share some documents for the same?

martha.nolan
2021-11-12 14:51
Yeah, an example sounds good - not sure about a specific class. Ultimately I guess it would just be adding whatever is in `withQuery()` to the query field of the request which can be achieved using a normal interaction.

megan.twyver
2021-11-12 18:39
has joined #pact-js

danieljak
2021-11-13 10:04
Ohh ok good to know, I'll try to think of how to manage it then Thx!

mischa.molhoek
2021-11-14 09:42
has joined #pact-js

69vron
2021-11-15 01:35
has joined #pact-js

tjones
2021-11-15 05:07
Can you share the exact error you're getting? I don't think pact is likely to be the culprit, but we can take a look

matt.fellows
2021-11-15 05:22
I'd really suggest making a minimal example without your code, and then adding dependencies back in until it fails

matt.fellows
2021-11-15 05:23
Basically, you will need to bisect the problem. From our standpoint, we can't tell what you're doing or what could be wrong

james.sawle
2021-11-15 08:49
has joined #pact-js

pete.watts
2021-11-15 12:46
has joined #pact-js

akanksha.sharma
2021-11-15 14:11
Hi, Need following information: ? Does Pact support producer driven contract testing, if yes can someone please share sample examples and best practices for Producer driven contract testing. ? we have developed some tests with API Postman with hybrid framework(using postman for consumer side and node.js provider side) approach is there away integration of PACT ? so that way we can reuse same code inside PACT.

esparga
2021-11-15 15:57
Hi All

esparga
2021-11-15 15:58
i was trying to test a pact contract like its described in the article https://codersociety.com/blog/articles/contract-testing-pact

esparga
2021-11-15 15:59
and when i run the script npm run test:consumer i get this error

esparga
2021-11-15 16:00
pact-node@9.16.5: The pact mock service doesnt appear to be running

esparga
2021-11-15 16:00
and it says to check the logs created..but the log file is empty

esparga
2021-11-15 16:02
how to run this ?pack mock service??

joshua.badger
2021-11-15 17:10
has joined #pact-js

matt.fellows
2021-11-15 22:12
You sort of can, but you still need to write the consumer tests first. Can you explain specifically what you mean by that?

matt.fellows
2021-11-15 22:13
Pactflow has an option that allows provider driven contracts called bi-directional contracts: https://docs.pactflow.io/docs/workshops/bi-directional

matt.fellows
2021-11-15 22:14
> we have developed some tests with API Postman with hybrid framework(using postman for consumer side and node.js provider side) approach is there away integration of PACT ? so that way we can reuse same code inside PACT. that?s the idea of bi-directional, you can convert existisg tests into a pact file

matt.fellows
2021-11-15 22:25
Can you please set the log level to debug and share the output?

tjones
2021-11-15 23:02
The log file will be empty because the server writes the log file and isn't running. The error message > Please check the logs *above* to ensure that there are no pact service startup failure (emphasis added) means to check the logs during the test output to see if the startup failed.

esparga
2021-11-16 09:12
In fact? there are no failures at start :(

esparga
2021-11-16 09:34
when we run the ?npm run test:consumer? which calls the ?mocha consumer.spec.js? ?dont we must have the server running first? i mean..the provider?

akanksha.sharma
2021-11-16 10:54
https://levelup.gitconnected.com/api-contract-testing-with-postman-a8af93e79d5 Please go through this blog. I implemented my hybrid framework as per this where Postman is used for consumer side to create Pacts and Nodejs for provider side.

tjones
2021-11-16 14:31
No, you need to start the pact mock server.

tjones
2021-11-16 14:32
Although, looking at that it looks like your before all hook is failing

tjones
2021-11-16 14:32
According the the error message, have you confirmed that you are calling `setup()`?

tjones
2021-11-16 14:33
Have you checked that you wait for that promise before doing the rest of your tests?

tjones
2021-11-16 14:35
according to that test output, both the before all and the after all hooks are failing.

tjones
2021-11-16 14:35
if the above doesn't help, share your test code and we'll take a look

esparga
2021-11-16 16:16
Hi @tjones I'm gonna paste here my code with printscreens.. (sorry about that but my working machine doesn't have access to slack) :(

esparga
2021-11-16 16:21
It's quite simple because it's the 5-minute-getting-started-guide from http://pact.io

esparga
2021-11-16 16:25
this last file is the consumer.spec.js

matt.fellows
2021-11-16 20:39
Can you please set log level to debug and then share those logs?

matt.fellows
2021-11-16 20:39
Also, I really wouldn't copy that because it's designed to run in a browser (hence why mocha is run programmatically)


omarsaddaoui
2021-11-17 02:55
has joined #pact-js

esparga
2021-11-17 09:34
@matt.fellows i setted the log level to debug and it goes like this

matt.fellows
2021-11-17 09:44
Can you please try sharing the mock service directly: https://github.com/pact-foundation/pact-js/#debugging

matt.fellows
2021-11-17 09:44
It looks like it's not starting

matt.fellows
2021-11-17 09:47
If i were to guess the problems 1. Corporate proxy interfering with the install and corrupting the binary we run 2. Windows long path issue



esparga
2021-11-17 09:59
and both services are running ?they start succesfully

esparga
2021-11-17 09:59
./node_modules/.bin/pact-mock-service

esparga
2021-11-17 09:59
```./node_modules/.bin/pact-provider-verifier```

matt.fellows
2021-11-17 10:00
thx

matt.fellows
2021-11-17 10:00
can you run the command you see in the log output? Perhaps one of those paths doesn?t exist?

matt.fellows
2021-11-17 10:00
(or something else is at play)

matt.fellows
2021-11-17 10:00
what version are you running, also?

esparga
2021-11-17 10:01
but i noticed that the logs?mentions using the cmd.exe standalone/win32-1-70-2/bin/pact-mock-service-bat

esparga
2021-11-17 10:01
and i cannot find that file :disappointed:

esparga
2021-11-17 10:02
version:_ pact-foundation/pac 9.1.0

esparga
2021-11-17 10:02
pact-node 10.2.4

matt.fellows
2021-11-17 10:05
something not right there

matt.fellows
2021-11-17 10:06
the version of node I can see running is super old (9.0.7)

matt.fellows
2021-11-17 10:06
I?d recommend just starting with a proper github downloadable example


esparga
2021-11-17 10:38
Just one more question Matt

esparga
2021-11-17 10:39
im on a windows machine

esparga
2021-11-17 10:39
and when i try to lunch the project using "node index"

esparga
2021-11-17 10:39
it trys to lunch the pact service using cmd.exe as you can see it here

esparga
2021-11-17 10:40
and this doesnt work....because its trying to look for a folder called standalone

esparga
2021-11-17 10:41
but if i try to lunch the service in VS Code in a terminal bash it works

esparga
2021-11-17 10:41
(instead of using cmd.exe)

esparga
2021-11-17 10:41
the question is... is there a way to force it not to use cms.exe and the standalone folder?

esparga
2021-11-17 10:42
and just use whatever there is inside node_modules/.bin ?

matt.fellows
2021-11-17 11:34
> the question is... is there a way to force it not to use cms.exe and the standalone folder? cms.exe? Is that being used?

matt.fellows
2021-11-17 12:34
oh sorry, slack collapsed the messages above so it didn?t make sense

matt.fellows
2021-11-17 12:35
There should be a standalone folder in your node_modules directory somewhere, it does sound like something has gone awry though

matt.fellows
2021-11-17 12:35
I?d suggest starting with a known working github repository, not the 5 minute guide (that?s really just designed to teach the concepts in the browser and not to be downloaded)

mbyrne
2021-11-17 14:23
has joined #pact-js

martha.nolan
2021-11-17 15:49
Hey @matt.fellows! Is there a way of having a dynamic key in an interaction - so for example a response could be `programme: {}` OR `episode:{}` where the key could be one of a finite list?

matthew.drill
2021-11-18 01:08
has joined #pact-js

tjones
2021-11-18 02:21
That's an old version of pact - I'd start with one of the newer ones, as we fixed some issues to do with windows within the last couple of years.

matt.fellows
2021-11-18 02:42
I?d really like to get rid of the 5 minute guide and point people at the katacoda. I think they are much more reliable and work better

matt.fellows
2021-11-18 02:42
I know we had a few people that said the 5 minute guide is good, but I believe the katacoda experience is much better and more easily contributed to because the source is on Github

matt.fellows
2021-11-18 02:43
the downside is they aren?t embedded in our docs, like the 5 minute guide

esparga
2021-11-18 11:53
@tjones but this version https://github.com/pactflow/example-consumer is a complex one which is using pactflow? is there any other simpler? without using pactflow? just for testing

esparga
2021-11-18 11:53
@matt.fellows what is that katakoda all about?

james.halsall
2021-11-18 12:02
has joined #pact-js

matt.fellows
2021-11-18 12:28
Katacoda tutorials are referenced here, we should get them into the http://docs.pact.io website also: https://docs.pactflow.io/docs/tutorials

matt.fellows
2021-11-18 12:29
You don?t need to use Pactflow for the example consumer, the consumer tests can run without it

tausif2909
2021-11-19 05:57
While adding query Parameter to the request I get this error while running consumer tests (I am using PactV3): `Listing taxonomies` `[2021-11-19T05:36:06Z ERROR pact_js_v3] Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string` `1) Get object for listing taxonomies` `Get object for listing taxonomies:` `Error: Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string` `at PactV3.withRequest (node_modules\@pact-foundation\pact\src\v3\pact.js:90:19)` `at Context.<anonymous> (test\pact\my-test-service.js:49:5)` `at processImmediate (internal/timers.js:464:21)` Any idea What I am doing wrong

tjones
2021-11-19 05:57
How are you adding the query parameter?

tausif2909
2021-11-19 05:58
```it('Get object for listing taxonomies', () => { provider .given('Get object for listing taxonomies') .uponReceiving('Get object for listing taxonomies') .withRequest({ method: 'GET', path: '/api/taxonomies', query: { accountId: term({ generate: '4', matcher: '4' }), enabled: term({ generate: 'true', matcher: 'true' }), displayInApps: term({ generate: 'true', matcher: 'true|false' }) } }) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8' }, body: taxonomies }); return provider.executeTest(async (mockserver) => { const response = await needle('get', `http://localhost:${port}/api/taxonomies?accountId=4&enabled=true&displayInApps=true`, requestOptions); expect(response.statusCode).to.equal(200); }); });``` Here is the code

tjones
2021-11-19 05:58
where does `term` come from?

uglyog
2021-11-19 05:59
I guess that is the V2 function for a regex matcher. We should add support for automatically converting them to the V3 ones.

matt.fellows
2021-11-19 06:00
ah, looks like you?re using the V2 matchers in the v3 package. We ought to guard against that situation

tausif2909
2021-11-19 06:00
```const { term } = pact.Matchers;``` Do I need to use `term` as V3 matcher?

uglyog
2021-11-19 06:01
No, in V3 it is probably called `regex`

matt.fellows
2021-11-19 06:02
The matchers you should use are in the same package as the `PactV3` class


tausif2909
2021-11-19 06:06
```const { string, term, like, integer, fromProviderState, } = MatchersV3;``` I have added term as the matcher but getting error like `TypeError: term is not a function`

matt.fellows
2021-11-19 06:09
see Ron?s comments above

tjones
2021-11-19 06:09
`term` is not exported from V3, you'll want `regex`

tausif2909
2021-11-19 06:11
```.withRequest({ method: 'GET', path: '/api/taxonomies', query: { accountId: regex({ generate: '4', matcher: '4' }), enabled: regex({ generate: 'true', matcher: 'true' }), displayInApps: regex({ generate: 'true', matcher: 'true|false' }) } })``` I have used that too, I still get error like : ` Get object for listing taxonomies: Error: Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string at PactV3.withRequest (node_modules\@pact-foundation\pact\src\v3\pact.js:90:19) at Context.<anonymous> (test\pact\my-test-service.js:50:5) at processImmediate (internal/timers.js:464:21)`

matt.fellows
2021-11-19 06:18
The https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/v3/matchers.ts#L270 is different, it accepts two positional arguments not an object

tausif2909
2021-11-19 06:28
```query: { accountId: regex(integer,4), enabled: regex(boolean,true), displayInApps: regex(boolean,true), }``` You mean like this? I still get same error, I appreciate if you could share the the example

matt.fellows
2021-11-19 06:29
you can?t apply a regex to a boolean, for those you should just use the `like` matcher e.g. `like(true)`

matt.fellows
2021-11-19 06:30
the `accountId` is also not something you want to regex looking at your code, you just want it to be `like(4)` right? a number?

tjones
2021-11-19 06:37
Although, if it's in the query string, you probably want a string matcher that matches the strings you want

tjones
2021-11-19 06:37
because the query is a string

matt.fellows
2021-11-19 06:38
good pickup, it was indented so far I didn?t notice that

tausif2909
2021-11-19 06:38
```query: { accountId: like(4), enabled: like(true), displayInApps: like(true) }``` Still same error :disappointed: : `Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string`

matt.fellows
2021-11-19 06:38
ha, yeah Tim just found that you?re doing this on a query *string*

tjones
2021-11-19 06:38
you need to match for strings.

matt.fellows
2021-11-19 06:39
my advice above was bad, sorry Tausif

matt.fellows
2021-11-19 06:39
What I said was correct, but you weren?t regexing a boolean, you were regexing a string representation of a boolean

matt.fellows
2021-11-19 06:41
something like this should work (just adjust for JS, I have typed this direct into slack): ```query: { accountId: regex(/[0-9]+/,"4"), enabled: regex(/true|false/,"true"), displayInApps: regex(/true|false/, "true"), }```

tausif2909
2021-11-19 06:44
let me try it

tausif2909
2021-11-19 06:50
That error seems gone, But now getting different error ` `1) Listing taxonomies` `Get object for listing taxonomies:` `Error: Test failed for the following reasons:` `Mock server failed with the following mismatches:` `0) The following request was expected but not received:` `Method: GET` `Path: /api/taxonomies/` `Query String: accountId=4&displayInApps=true&enabled=true` `at D:\git-directory\flex-search-app\Service\node_modules\@pact-foundation\pact\src\v3\pact.js:144:43``

tausif2909
2021-11-19 06:51
Sorry to bother you guys, This something I came across for the first time

tausif2909
2021-11-19 08:08
Any suggestion, Please? :point_up_2:

matt.fellows
2021-11-19 08:17
It looks pretty clear to me. Are you sending that request to the pact mock server?

matt.fellows
2021-11-19 08:22
In a pact test, you're mocking out the backend using Pact as the mock server. The mock gets validated so if you don't do what you said you would the test fails. Here pact is saying "you told me you were going to make this request but I never saw it"

tausif2909
2021-11-19 08:38
yes. sending it to pact mock server, I have done the same code on the other service, thats working fine, but not working here

tausif2909
2021-11-19 09:10
Finally solved the issue, Thanks alot for your time , help and support @matt.fellows @tjones @uglyog :+1:

matt.fellows
2021-11-19 09:54
What was it?

tausif2909
2021-11-19 10:12
Mismatch between port, Was causing unusual error.

tausif2909
2021-11-19 11:28
```const provider = new PactV3({ consumer: 'my-demo-app', provider: 'my-test-service', port: 18186, log: path.resolve(process.cwd(), '../', 'pact', `${providerName}.log`), dir: path.resolve(process.cwd(), '../', 'pact'), logLevel: 'DEBUG', spec: 2 });``` logging with this code is not working in PactV3, With older version it was working fine, Have we changed the logging with PactV3?

matt.fellows
2021-11-19 12:07
Which property? It currently doesn't log to a separate file, check the method signature for what you can pass in

esparga
2021-11-19 14:03
Hi Again

esparga
2021-11-19 14:03
sorry for bothering... with the same issue

esparga
2021-11-19 14:04
i was able to launch the stanalone version from the tests... (apparently) but now im getting this error

esparga
2021-11-19 14:05
its saying the WeBrick:HTTPServer is started...it has pid and port assigned

esparga
2021-11-19 14:06
but inside beforeAll its saying the mock service is not running...

tjones
2021-11-19 14:08
This is usually a race condition. Have you followed all the recommended steps in the error message?

chvram
2021-11-19 14:09
has joined #pact-js


esparga
2021-11-19 14:14
im really lost in here :disappointed:

akhandalmani.malik
2021-11-19 14:17
has joined #pact-js

esparga
2021-11-19 14:19
the host.. can it be 127.0.0.1?

esparga
2021-11-19 14:26
it seems so...i removed the host..and it defaults to 127.0.0.1

elias.frykholm
2021-11-19 15:17
has joined #pact-js

martin.carlin
2021-11-19 15:52
has joined #pact-js

paul.nardone
2021-11-19 16:12
has joined #pact-js

emily
2021-11-19 18:56
has joined #pact-js

tjones
2021-11-20 12:47
Hm. It looks like your before all hook is failing, but I'm not seeing any error messages, which is strange

tjones
2021-11-20 12:48
can you try catching the promise in the before all, and see what the failure is?

pietrucha.bartosz
2021-11-20 13:47
has joined #pact-js

armen.chuljyan
2021-11-21 01:58
has joined #pact-js

mastrobardo
2021-11-21 11:42
has joined #pact-js

fed
2021-11-22 04:20
has joined #pact-js

tausif2909
2021-11-22 05:34
```D:\git-directory\my-test-app\Service\publishPact>node publishToPactBroker.js [2021-11-22T05:28:30.307Z] INFO: pact-node@6.21.5/21900 on tshaikh: Publishing Pacts to Broker [2021-11-22T05:28:30.309Z] INFO: pact-node@6.21.5/21900 on tshaikh: Publishing pacts to broker at: https://pact.test.net/ [2021-11-22T05:28:30.314Z] INFO: pact-node@6.21.5/21900 on tshaikh: Created 'standalone\win32-1.63.0\bin\pact-broker.bat publish 'D:\git-directory\my-test-app\pact\my-test-app-f lex-taxonomyWIP-service.json' --broker-base-url 'https://pact.test.net/' --consumer-app-version '0.0.0-DEV'' process with PID: 9040 [2021-11-22T05:28:45.238Z] WARN: pact-node@6.21.5/21900 on tshaikh: Pact exited with code 1. [2021-11-22T05:28:45.238Z] ERROR: pact-node@6.21.5/21900 on tshaikh: Could not publish pact: Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service /node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 1 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service /node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 2 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service /node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 3 of 3 Failed to publish my-test-app/my-test-service pact due to error: OpenSSL::SSL::SSLError - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certifica te verify failed One or more pacts failed to be published Publishing my-test-app/my-test-service pact to pact broker at https://pact.test.net/ Something went wrong while pushing pact for taxonomy Error: Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificat e verify failed D:/git-directory/my-test-app/Service/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_bro ker/client/pacts.rb:35:in `get', attempt 1 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service/nod e_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 2 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service/nod e_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 3 of 3 Failed to publish my-test-app/my-test-service pact due to error: OpenSSL::SSL::SSLError - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate v erify failed One or more pacts failed to be published Publishing my-test-app/my-test-service pact to pact broker at https://pact.test.net// at ChildProcess.<anonymous> (D:\git-directory\my-test-app\Service\node_modules\@pact-foundation\pact-node\src\publisher.js:65:40) at Object.onceWrapper (events.js:482:26) at ChildProcess.emit (events.js:387:35) at maybeClose (internal/child_process.js:1055:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)``` Publishing pact causing SSL error, I am on "@pact-foundation/pact": "10.0.0-beta.53", How do I resolve the error?

tjones
2021-11-22 05:51
Is your broker hosted with custom certs?

tjones
2021-11-22 05:54
Please try the latest version (10.0.0-beta.54)

tausif2909
2021-11-22 06:01
ok, let me try that

matt.fellows
2021-11-22 06:17
is it a self-signed certificate and is it in the certificate store? Tim is probably right, in that the latest version should resolve it if that?s the case

tausif2909
2021-11-22 06:23
No luck, Same error :disappointed:

tausif2909
2021-11-22 06:27
no, same is working fine in the jenkins pipeline

tausif2909
2021-11-22 06:28
This is i am trying in my local

tjones
2021-11-22 06:28
If it

tjones
2021-11-22 06:28
If it's broken locally, I would guess it's a certificate issue. Are you able to load your broker from a curl command?

matt.fellows
2021-11-22 06:32
`curl https://pact.test.net` <- if you can please post the results of that (I?m pretty sure powershell has an alias for that)

matt.fellows
2021-11-22 06:32
but also, real curl would be better

tausif2909
2021-11-22 06:52
let me try with the curl command

tausif2909
2021-11-22 07:32
```>curl https://pact.test.net/ {"_links":{"self":{"href":"https://pact.ooflex.net","title":"Index","templated":false},"pb:publish-pact":{"href":"https://pact.test.net/pacts/provider/{provider}/consumer/{consumer}/ve rsion/{consumerApplicationVersion}","title":"Publish a pact","templated":true},"pb:publish-contracts":{"href":"https://pact.test.net/contracts/publish","title":"Publish contracts","tem plated":false},"pb:latest-pact-versions":{"href":"https://pact.test.net/pacts/latest","title":"Latest pact versions","templated":false},"pb:tagged-pact-versions":{"href":"https://pact. http://ooflex.net/pacts/provider/{provider}/consumer/{consumer}/tag/{tag}%22,%22title%22:%22All versions of a pact for a given consumer, provider and consumer version tag","templated":false},"pb:pactic ipants":{"href":"https://pact.test.net/pacticipants","title":"Pacticipants","templated":false},"pb:pacticipant":{"href":"https://pact.test.net/pacticipants/{pacticipant}","title":"Fe tch pacticipant by name","templated":true},"pb:latest-provider-pacts":{"href":"https://pact.test.net/pacts/provider/{provider}/latest","title":"Latest pacts by provider","templated":tr ue},"pb:latest-provider-pacts-with-tag":{"href":"https://pact.test.net/pacts/provider/{provider}/latest/{tag}","title":"Latest pacts for provider with the specified tag","templated":tr ue},"pb:provider-pacts-with-tag":{"href":"https://pact.test.net/pacts/provider/{provider}/tag/{tag}","title":"All pact versions for the provider with the specified consumer version tag ","templated":true},"pb:provider-pacts":{"href":"https://pact.test.net/pacts/provider/{provider}","title":"All pact versions for the specified provider","templated":true},"pb:latest-ve rsion":{"href":"https://pact.test.net/pacticipants/{pacticipant}/latest-version","title":"Latest pacticipant version","templated":true},"pb:latest-tagged-version":{"href":"https://pact .http://ooflex.net/pacticipants/{pacticipant}/latest-version/{tag}%22,%22title%22:%22Latest pacticipant version with the specified tag","templated":true},"pb:webhooks":{"href":"https://pact.test.net/ webhooks","title":"Webhooks","templated":false},"pb:webhook":{"href":"https://pact.test.net/webhooks/{uuid}","title":"Webhook","templated":true},"pb:integrations":{"href":"https://pact .http://ooflex.net/integrations%22,%22title%22:%22Integrations%22,%22templated%22:false},"pb:pacticipant-version-tag":{"href":"https://pact.test.net/pacticipants/{pacticipant}/versions/{version}/tags/{tag} ","title":"Get, create or delete a tag for a pacticipant version","templated":true},"pb:pacticipant-version":{"href":"https://pact.test.net/pacticipants/{pacticipant}/versions/{version }","title":"Get, create or delete a pacticipant version","templated":true},"pb:metrics":{"href":"https://pact.test.net/metrics","title":"Get Pact Broker metrics"},"pb:can-i-deploy-pact icipant-version-to-tag":{"href":"https://pact.test.net/can-i-deploy?pacticipant={pacticipant}&version={version}&to={tag}","title":"Determine if an application can be safely deployed to an environment identified by the given tag","templated":true},"pb:provider-pacts-for-verification":{"href":"https://pact.test.net/pacts/provider/{provider}/for-verification","title":" Pact versions to be verified for the specified provider","templated":true},"beta:provider-pacts-for-verification":{"name":"beta","href":"https://pact.test.net/pacts/provider/{provider} /for-verification","title":"DEPRECATED - please use pb:provider-pacts-for-verification","templated":true},"curies":[{"name":"pb","href":"https://pact.test.net/doc/{rel}?context=index", "templated":true},{"name":"beta","href":"https://pact.test.net/doc/{rel}?context=index","templated":true}]}}``` Thats the result

matt.fellows
2021-11-22 07:38
Is CI Linux or windows?

matt.fellows
2021-11-22 07:38
Can you please check you're on the latest and if it still doesn't work please set log level to trace and share

tausif2909
2021-11-22 07:47
ok sure.

tausif2909
2021-11-22 07:47
I am on windows

tumunshaily
2021-11-22 07:54
has joined #pact-js

matt.fellows
2021-11-22 08:25
What about CI?

tausif2909
2021-11-22 08:43
its linux

esparga
2021-11-22 09:21
Hi @tjones i was able to figure it out!! it was a proxy problem... im behind a corporate proxy...and somehow i dont know why... when the tests are running it fails saying the service is not up...which it is...as we can see it in the logs..

esparga
2021-11-22 09:21
if i set up correctly the proxy...it works ....

esparga
2021-11-22 09:21
during the tests...it makes some external calls?

tjones
2021-11-22 09:22
Ah, great! No, it shouldn?t make external calls during the tests. But it does need to contact the broker that you have configured (where the ssl error was)

yunfeng.wang
2021-11-22 09:25
has joined #pact-js

matt.fellows
2021-11-22 09:48
the proxy config can still interfere with local calls - i.e. calls from your machine?to your machine

matt.fellows
2021-11-22 09:48
that?s what proxies do

matt.fellows
2021-11-22 09:48
presumably, you fixed it by setting up `http_proxy` or `no_proxy` environment variables?

matt.fellows
2021-11-22 09:49
This could definitely be checked in our boot routine. People talk about `null` being the Billion dollar mistake. If that?s true, then proxies and corporate firewalls are the trillion dollar mistake

esparga
2021-11-22 10:09
Hi @matt.fellows yes..i had to set up the no_proxy and http_proxy env vars

esparga
2021-11-22 10:10
thanks everyone to all your availability!

matt.fellows
2021-11-22 11:10
You?re welcome. It?s such a nefarious bug to diagnose - thanks for your patience

matt.fellows
2021-11-22 11:27
Added an item on corporate proxies to our troubleshooting section: https://github.com/pact-foundation/pact-js#corporate-proxies--firewalls

christos.litsas
2021-11-23 13:05
has joined #pact-js

walter.psjr
2021-11-23 17:39
has joined #pact-js

john
2021-11-24 05:55
so just a quick question, i had a debate with my colleague over pact and he was saying that I need to render a react component to create the contract test? I was under the impressiont hat react doesnt matter and we should use the api that the react component uses to generate the consumer test?

matt.fellows
2021-11-24 05:55
no you don?t need to render the react component - that?s definitely not recommended

john
2021-11-24 05:55
yeah thats what i said

matt.fellows
2021-11-24 05:55
you?re impression is correct

tjones
2021-11-24 05:56
We wholeheartedly agree with you :slightly_smiling_face:

matt.fellows
2021-11-24 05:56
Old react code, so apologies, but this example is a react code base and we test the `API` class, not the React component. i.e. the scope of the test is the API client used by this bit of code: https://github.com/pactflow/example-consumer/blob/master/src/ProductPage.js#L24-L28


john
2021-11-24 05:57
yeah so basically import the api that the react class uses intot he consumer test right?

matt.fellows
2021-11-24 05:57
yeah.

matt.fellows
2021-11-24 05:57
if your react code is directly calling APIs, that should call for a refactor anyway IMO

john
2021-11-24 05:59
so another thing, we talked about was that we have a graph ql query. Is it best practise to base the consumer test on just the returned fields that the react component is actually using?


tjones
2021-11-24 05:59
That's right

matt.fellows
2021-11-24 05:59
yes. But isn?t that what graphql is for - only fetching the things you need? (so both the query and the pact tests should only cover what you need)

tjones
2021-11-24 06:00
Pact isn't a full description of the API, it's the parts of the API that your consumer needs (which may be only partial responses)

john
2021-11-24 06:02
so basically create a consumer pact for only the stuff that is being used by the react component for instance

john
2021-11-24 06:03
awesome thanks for those responses guys just my colleague and I are fmbling through this stuff for the first time

tjones
2021-11-24 06:05
You're welcome!

harwin1494
2021-11-24 06:26
An add-on question to this, is it really required for us to call an API in the consumer test to create an interaction consisting of expected requests and responses?

matt.fellows
2021-11-24 06:29
yes.

matt.fellows
2021-11-24 06:30
Why do you think you shouldn?t?

matt.fellows
2021-11-24 06:30
(asking to fully understand where you?re coming from)

harwin1494
2021-11-24 06:37
I am writing a test for '/getUserprofile' endpoint which requires a cookie as a header which is to be fetched from '/authenticate' endpoint (as there is no other identifier to get the profile for a particular user), but the actual '/getUserprofile' api doesnt include any cookie in the header (just 'content-type' is present in the headers), so I am trying to avoid calling it altogether.

matt.fellows
2021-11-24 06:42
in a pact test, you should stub out external dependencies. If I understand correctly, your `/getUserprofile` endpoint calls `/authenticate` to get a cookie, and then uses this somehow? IF so, you should stub out calls to `/authenticate` in this pact test, and then write a separate pact tests for `/authenticate`

john
2021-11-24 06:49
Hey one last question I forgot to ask earlier. Say for example if i have an api but it is wrapped in an aws lambda event do i base the contract on the wrapped aws lambda or the api? Sorry if that makes no sense

matt.fellows
2021-11-24 06:52
is it an HTTP or async lambda? i.e. behind AWS gateway or a queue like SNS/SQS/Kinesis?

john
2021-11-24 06:55
i think we might have a mixture of both depending on the service repo etc



harwin1494
2021-11-24 07:33
No, these endpoints are called separately. After calling the '/authenticate', the cookie generated gets sent in the headers of the '/getUserprofile' endpoint (GET call). This has been achieved in postman via request chaining.

harwin1494
2021-11-24 07:54
It was related to the jest config only as suggested by Matt, thanks a lot.

steveforwork2
2021-11-24 08:47
has joined #pact-js

matt.fellows
2021-11-24 08:52
Which config item Garwin? That would be helpful to know and we can add to our troubleshooting guide if it makes sense

matt.fellows
2021-11-24 08:54
I see. In pact tests, each interaction should be tested in isolation

matt.fellows
2021-11-24 08:55
Trying to replicate a postman series of tests in pact is not a great idea, because it's a functional testing tool

matt.fellows
2021-11-24 08:56
A consumer pact test can use a fake cookie because it's a unit test. So you don't need to chain


matt.fellows
2021-11-24 09:02
Isolation is the key.

esparga
2021-11-24 09:31
Hi Guys! @matt.fellows @tjones im making the provider part..and i've some doubts about the mandatory parameters

esparga
2021-11-24 09:31
whats the difference between pactBrokerUrl and providerBaseUrl?

tjones
2021-11-24 09:36
One is for the pact broker (which gives the verifier the contract), and the other is for your provider (the thing you are testing)

esparga
2021-11-24 10:32
the pactBrokerUrl i understand....but...when we are verifying the pact for the first time (from the provider)...and assuming the pact was published with the consumer side... which 'providerBaseUrl' should we use...? just the name of the provider?

esparga
2021-11-24 10:32
the 'url' part is somehow confusing

akke.luukkonen
2021-11-24 10:38
What URL is your provider running at & where do the packets from the Consumer need to be sent? That is the Provider base URL, e.g. http://localhost:7071/api

matt.fellows
2021-11-24 10:54
Provider verification takes a pact from the broker (`pactBrokerUrl` and related parameters) and then replays the tests against your locally running provider (`providerBaseUrl`)

matt.fellows
2021-11-24 10:54
so you need to have the provider running locally, and point your verification test at the provider

matt.fellows
2021-11-24 10:55
> the ?url? part is somehow confusing what?s confusing about the url bit?

fredrik.ostling
2021-11-24 11:56
has joined #pact-js

esparga
2021-11-24 12:20
ok understood now... :wink: "and then replays the tests against your locally running provider (`providerBaseUrl`)"

esparga
2021-11-24 12:20
its the url to the provider test which is localhost

esparga
2021-11-24 12:20
got it! thanks

esparga
2021-11-24 13:16
One test fails with this msg

esparga
2021-11-24 13:16
But the provider is like this

esparga
2021-11-24 13:17
Is there a way to force it to not use the charset-utf-8?

esparga
2021-11-24 13:18
For some reason even if I just use ?application/json? as the content-type it always assume that is ?application/json; charset-utf-8;?

matt.fellows
2021-11-24 13:36
Are you using `res.json(...)` later? That might override the header

jorge.nunez
2021-11-24 14:28
has joined #pact-js

leonardo.viana
2021-11-24 15:51
Hi all. Does pactjs v3 beta support nodejs 16? We are considering moving to that version, but I'd like to get confirmation on support first.

asradhakrishnan
2021-11-24 17:20
has joined #pact-js

asradhakrishnan
2021-11-24 17:22
hi All, Im writing contract tests on consumer side. At the end of my test when the pact file is generated in the /pacts folder, I see that the response body is encoded in base-64 format. Can someone help me in decoding that before the response body is written to the pact file?

mike.geeves064
2021-11-24 19:21
The body should be in relation to the Pact test and behaviour you have written, it has what you expect to receive. Can you provide some more details about the actual test performed that generated the Pact file. Also, what are you then wanting to achieve from it, by decoding?

asradhakrishnan
2021-11-24 19:22
@mike.geeves064 thanks for your reply. So, Ive specified response as such ```return { status: 200, headers: { "Content-Type": "application/json" }, body: expectedBody };```

asradhakrishnan
2021-11-24 19:22
i tried adding the charset-utf-8 in the the content Type, but no luck

mike.geeves064
2021-11-24 19:23
And is expectedBody just some json?

mike.geeves064
2021-11-24 19:25
As in, if you look at the example: https://github.com/pact-foundation/pact-js#consumer-side-testing you have the EXPECTED_BODY relating to the ``` willRespondWith: { status: 200, headers: { "Content-Type": "application/json" }, body: EXPECTED_BODY, },```

asradhakrishnan
2021-11-24 19:26
expected body is of type, as follows: ```event: data id: event-1 data: <JSON>```

mike.geeves064
2021-11-24 19:27
Hang on so this is a consumer test? Might need a bit more context, which examples/tutorial etc are you following?

asradhakrishnan
2021-11-24 19:28
yes its a consumer test. So im writing these tests for my company where we expect SSE type response from the provider.

asradhakrishnan
2021-11-24 19:29
not following anything specific tutorial for this one

mike.geeves064
2021-11-24 19:35
Try having a look through one of the workshops/tutorials e.g. https://github.com/pact-foundation/pact-workshop-js/tree/step1#step-1---simple-consumer-calling-provider I think you might have the test setup and consumer not quite right...

asradhakrishnan
2021-11-24 19:50
this is what my provider object looks like ```return new PactV3({ consumer: <consumer_name>, provider: <provider_name>, log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });```

mike.geeves064
2021-11-24 20:10
Ok, but what does your actual test look like, is it like in the example, with the will respond with etc

asradhakrishnan
2021-11-24 21:31
so the `willRespond(expectedResponse)` where the expectedResponse is in form of a string

matt.fellows
2021-11-24 21:44
can you please share the pact file (specifically the interaction with base64 encoding) and the full test example?

matt.fellows
2021-11-24 21:44
it might be base64 encoded if the request/response content type is detected as binary

asradhakrishnan
2021-11-24 21:51
this is what the response in the generated pact file looks like ```"response": { "body": "<encoded response>", "headers": { "Content-Type": "application/json" }, "status": 200 }```

asradhakrishnan
2021-11-24 21:51
sorry cant divulge much in the response body since its a sensitive info in my company. :slightly_smiling_face:

matt.fellows
2021-11-24 21:58
my suggestion is to create an example that doesn?t include your company info that reproduces the problem

matt.fellows
2021-11-24 21:58
see howtorepro for what this means


asradhakrishnan
2021-11-24 22:08
```function createRequest(...modules) { return { method: "GET", path: <endpoint>, query: {}, headers: {Accept: "text/event-stream"} }; } function createProvider() { return new PactV3({ consumer: "consumer_name", provider: "provide_name", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 }); } function createResponse(expectedBody) { return { status: 200, headers: { "Content-Type": "application/json" }, body: expectedBody } }```

asradhakrishnan
2021-11-24 22:10
this is what my test looks like ```it('Runs the test', () => { const param = stringParam; provider .given(`item exists`) .uponReceiving("request") .withRequest(createRequest(param)) .willRespondWith(createResponse(stringParam));```

asradhakrishnan
2021-11-24 22:13
@matt.fellows ^^

matt.fellows
2021-11-24 22:17
so it?s possible that the request body will be base64 encoded. but it would/should be decoded on the provider verification side - is it not?

matt.fellows
2021-11-24 22:17
also that?s not a reproducible example. I should be able to run the code locally to be able to reproduce it

tjones
2021-11-24 22:27
Unfortunately, not at this time (this is one of the blockers for release)

edouard.lopez
2021-11-25 11:01
has joined #pact-js

esparga
2021-11-25 11:23
Hi Matt, yes i'm using res.json later on to send the response... which are the options here?

matt.fellows
2021-11-25 13:39
Probably best to read up on the express docs.

matt.fellows
2021-11-25 13:39
But if the provider always responds with the charset, update the consumer test

maxkitzing
2021-11-25 17:49
has joined #pact-js

cristian.carrillo
2021-11-26 00:06
has joined #pact-js

john
2021-11-26 01:47
I tried to do the npm ci and rerun but i get the same error

matt.fellows
2021-11-26 02:33
can you please provide the exact steps to reproduce the problem?

matt.fellows
2021-11-26 02:34
Just ran the examples locally myself and they work just fine

christoph.oswald
2021-11-26 09:53
has joined #pact-js

gjourdanweil
2021-11-26 14:39
has joined #pact-js

sean.pike
2021-11-26 14:48
has joined #pact-js

tausif2909
2021-11-29 05:02
```[4/4] Building fresh packages... info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. error /opt/flex-service/node_modules/ffi-napi: Command failed. Exit code: 1 Command: node-gyp-build Arguments: Directory: /opt/flex-service/node_modules/ffi-napi Output: events.js:377 throw er; // Unhandled 'error' event ^ Error: spawn node-gyp ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:82:21) Emitted 'error' event on ChildProcess instance at: at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:82:21) { errno: -2, code: 'ENOENT', syscall: 'spawn node-gyp', path: 'node-gyp', spawnargs: [ 'rebuild' ]``` After upgrading pact consumer test to V3 ("@pact-foundation/pact": "10.0.0-beta.51") , I get above error in jenkins pipeline while installing dependencies. Same was working fine in my local (Windows machine), But our jenkins pipeline is on linux, I was able to reproduce the issue on a local system with linux OS.

tausif2909
2021-11-29 05:40
Any idea on this :point_up_2:? @matt.fellows @tjones

tjones
2021-11-29 06:34
Hi Tausif! You don't need to tag us, we get notified when questions are posted in this channel already, and will answer when we can. Can you open an issue here please? https://github.com/pact-foundation/pact-js/issues/new/choose The issue template asks all the standard debugging questions, like node versions, etc. With the beta, we're currently having some issues with node 14+, preventing builds on some systems. However, that looks like a yarn error before the build failure would happen, rather than a pact error. It looks like it's unable to spawn node-gyp. I know that yarn has broken a number of expectations about the way the install process works, so I would start there. Are you using yarn 2? I would try: Updating to the latest supported version of node within that major release. While you're at it, try updating the beta version too (I don't think it will fix this error, but "try the latest version" is the first step in our debugging instructions).

tausif2909
2021-11-29 06:41
No, I am not using yarn2, with non beta pact version its working fine, whenever I upgrade it to the latest or any of beta version i start getting this error in the build. I have implemented same thing on another service and thats working well, I dont know why its crashing on this particular service

tausif2909
2021-11-29 06:42
and apologize for tagging.. usually I get the reply within a few mins. I thought you might have missed it, sorry once again for that

michael.bannister
2021-11-29 07:43
has joined #pact-js

harwin1494
2021-11-29 11:20
I got your point here and I can use a fake cookie, but the problem is, that the actual endpoint (i.e. in the source code) does not contain the cookie in its header, its just that I got to know about it through POSTMAN. So, I am unable to write a PACT test for it. I just need to know if I can add this header anyhow in the interaction (json) file , and I think that can be achieved if I dont call the actual endpoint in my test?

matt.fellows
2021-11-29 11:30
what does your actual provider need?

matt.fellows
2021-11-29 11:32
You mentioned above it needs a cookie. Does it not need a cookie?

matt.fellows
2021-11-29 11:33
It?s simple. Your consumer Pact tests should be a *unit test* of your API client code, where your API client is the piece of code that talks to the provider

matt.fellows
2021-11-29 11:33
Whatever your consumer code sends and expects to receive of the provider should go in the test

matt.fellows
2021-11-29 11:33
nothing more

matt.fellows
2021-11-29 11:34
If it needs to make a separate call to get credentials, you should mock or stub that out in your test as appropriate, to focus on the single interaction

matt.fellows
2021-11-29 11:34
if that piece of code needs to send a cookie to authenticate to the provider, it must be in the pact test. If it doesn?t, and that?s just something else another part of code does, it shouldn?t be in the pact test.


leonardo.viana
2021-11-29 18:24
Is there a timeline for when nodejs 16 support is planned on being added for pactjs v3 beta?

rjadams96
2021-11-29 18:47
has joined #pact-js

tjones
2021-11-29 22:23
No worries, it's no problem :slightly_smiling_face:

tjones
2021-11-29 22:24
Apologies that the beta isn't especially stable. I'm keen to confirm that this one isn't us though - if you could open an issue with all the details, that would be helpful

tjones
2021-11-29 22:43
Specifically, I'm keen to know which exact node version you are using

pavithz
2021-11-29 23:51
has joined #pact-js

mfellows_20211130
2021-11-30 06:57
has joined #pact-js

john
2021-11-30 07:31
when i run the consumer test, it should dump a pact into the pact folder right?

john
2021-11-30 07:32
for some reason when im running the consumer test nothing gets generated

tjones
2021-11-30 07:32
Yes, although we usually say "save" :wink:


tjones
2021-11-30 07:33
Can you share your test code / log output?

john
2021-11-30 07:33
save does soundd a tad more decent

john
2021-11-30 07:34
the log generates this

john
2021-11-30 07:34
```I, [2021-11-30T17:33:43.487014 #42518] INFO -- : Verifying - interactions matched I, [2021-11-30T17:33:43.490941 #42518] INFO -- : Cleared interactions```

john
2021-11-30 07:35
the test looks like this

john
2021-11-30 07:35
```describe('GraphQL example', () => { // Explicit longer timeout to account for Pact server needing to spin up // Was throwing timeout errors after default 5 second timeout jest.setTimeout(30000) const provider = new Pact({ log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), consumer: 'GraphQLConsumer', provider: 'GraphQLProvider' }) beforeEach(() => provider.setup()) afterEach(() => provider.finalize()) describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `query ProfileQuery { default } ` ) .withOperation('ProfilePageQuery') .withRequest({ path: 'http://localhost:9090/api/v2/graphql', method: 'POST' }) .withVariables({}) .willRespondWith({ status: 200, body: { id:1, username: 'default' } }) return provider.addInteraction(graphqlQuery) }) }) it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {}) console.log(account); return expect(account).to.deep.contain({ username: 'default' }) }) afterEach(() => provider.verify()) })```

matt.fellows
2021-11-30 07:38
The setup should be a before all, and finalise after all. You only need to call them once for the lifecycle of the whole suite

john
2021-11-30 07:41
do i need this as afterAll too? afterAll(() => provider.verify())

john
2021-11-30 07:43
it still doesnt seem to generate a pact

matt.fellows
2021-11-30 07:52
No, verification should happen per test

matt.fellows
2021-11-30 07:52
Please share the full log file. Also double check you haven't got other test running that may interfere with it?

john
2021-11-30 07:54
where is the full log file aved to

tjones
2021-11-30 08:09
If you're using Jest, you can use `jest-pact` which does all this setup for you

tjones
2021-11-30 08:10
```afterEach(() => provider.finalize())``` This is probably not right - you want to only do this once.

tjones
2021-11-30 08:10
Oh, Matt already said that.

tjones
2021-11-30 08:10
by full log, we mean the full test output

john
2021-11-30 08:14
```[2021-11-30 08:12:06.015 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Creating Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000} PASS tests/contract/profile-page-consumer.test.ts GraphQL example ? returns the correct response (34 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 2.79 s, estimated 3 s Ran all test suites matching /.\/tests\/contract\/profile-page-consumer.test.ts/i. [2021-11-30 08:12:06.577 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" [2021-11-30 08:12:06.615 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Pact File Written [2021-11-30 08:12:06.615 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Removing Pact process with PID: 54140 [2021-11-30 08:12:06.617 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Deleting Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000}```

matt.fellows
2021-11-30 08:15
Thanks. What does that .log file say?

john
2021-11-30 08:16
```I, [2021-11-30T18:12:06.607544 #54140] INFO -- : Verifying - interactions matched I, [2021-11-30T18:12:06.611469 #54140] INFO -- : Cleared interactions```

matt.fellows
2021-11-30 08:17
That's the full log? I... Don't think that's right

john
2021-11-30 08:18
thats all that is ther

john
2021-11-30 08:18
for some context, i am running a mock server thats only job is to return a test payload

matt.fellows
2021-11-30 08:18
Please set the log level to debug and share that terminal output. Something is out of whack

john
2021-11-30 08:19
where do i do that?

john
2021-11-30 08:19
in the package.json file?


john
2021-11-30 08:24
so i set the loglevel to debug

john
2021-11-30 08:24
i added this to the new Pact object

john
2021-11-30 08:24
logLevel: 'debug'

john
2021-11-30 08:25
but the log is the same

matt.fellows
2021-11-30 08:25
The terminal output should be different

john
2021-11-30 08:25
```[2021-11-30 08:25:32.086 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2021-11-30 08:25:32.087 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick::HTTPServer#start: pid=57771 port=3000```

john
2021-11-30 08:26
we brick doesnt sound good

abubics
2021-11-30 08:26
(It's a new R&M spin-off: web-Rick)

matt.fellows
2021-11-30 08:27
That's the entire terminal output?

john
2021-11-30 08:27
```[2021-11-30 08:25:32.153 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2021-11-30 08:25:32.086 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2021-11-30 08:25:32.087 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick::HTTPServer#start: pid=57771 port=3000 [2021-11-30 08:25:32.102 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Pact File Written [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Removing Pact process with PID: 57771 [2021-11-30 08:25:32.145 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Deleting Pact Server with options: ```

matt.fellows
2021-11-30 08:28
They're all info level messages, so something is not right. Are you sure the test you're running is the right one?

john
2021-11-30 08:30
```yarn test:consumer [2021-11-30 08:25:31.558 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Creating Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000} [2021-11-30 08:25:31.571 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Starting pact binary '/Users/Development/Work/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.80/pact/bin/pact-mock-service', with arguments [service --consumer GraphQLConsumer --pact_dir /Users/Development/Work/pacts --host 127.0.0.1 --log /Users/Development/Work/logs/mockserver-integration.log --pact-file-write-mode overwrite --port 3000 --provider GraphQLProvider --pact_specification_version 2] [2021-11-30 08:25:31.575 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Created '/Users/Development/Work/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.80/pact/bin/pact-mock-service' process with PID: 57771 PASS tests/contract/profile-page-consumer.test.ts GraphQL example ? returns the correct response (37 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 2.728 s, estimated 4 s Ran all test suites matching /.\/tests\/contract\/profile-page-consumer.test.ts/i. [2021-11-30 08:25:32.153 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2021-11-30 08:25:32.086 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2021-11-30 08:25:32.087 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick::HTTPServer#start: pid=57771 port=3000 [2021-11-30 08:25:32.102 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Pact File Written [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Removing Pact process with PID: 57771 [2021-11-30 08:25:32.145 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Deleting Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000}```

john
2021-11-30 08:30
thats the full output

john
2021-11-30 08:31
one question so the that pact object

john
2021-11-30 08:31
i have the port on 3000 but this mock server im running is on 9090

john
2021-11-30 08:32
so to be clear i had to pysically run the mock server in another terminal window

john
2021-11-30 08:32
while this test runs

matt.fellows
2021-11-30 08:35
Right, that information would have been useful

matt.fellows
2021-11-30 08:35
Why are you doing that?

tjones
2021-11-30 08:35
``` .withRequest({ path: 'http://localhost:9090/api/v2/graphql',``` This part is suspicious. I think it should just be the path, not the full URL

john
2021-11-30 08:36
so thats not the right way to do it presumably then lol

tjones
2021-11-30 08:36
No. The test starts the mock server for you

matt.fellows
2021-11-30 08:37
Are you following an example somewhere?

tjones
2021-11-30 08:37
If you're hitting the other mock server, it will be writing the pact ...somewhere else, wherever it's configured to

tjones
2021-11-30 08:37
but as Matt said... why are you running it separately?

tjones
2021-11-30 08:38
I have to head out, back later

matt.fellows
2021-11-30 08:38
I'd Love to know how you got to running your own mock server, and if we need to fix docs etc to clarify

john
2021-11-30 08:38
the reason was the way the developers wrote the graphql it wasnt easy just to import the client

john
2021-11-30 08:39
so the developers refactored their code to allow me to easly query the graphql

john
2021-11-30 08:39
but the when they handed it over they said the only way they could get it working was by starting the mock server they have

john
2021-11-30 08:39
and none oof us really know anything about pact

john
2021-11-30 08:40
so we query the graphql witht his function: ``` it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {}) return expect(account).to.deep.contain({ username: 'default' }) })```

matt.fellows
2021-11-30 08:40
And they've handed this over to you, I'm guessing maybe you're a tester/QA?

john
2021-11-30 08:40
well im certainly not a dev

john
2021-11-30 08:40
thats for sure

matt.fellows
2021-11-30 08:42
So separate problem, but I'd also be flagging this isn't ideal. Pact is really designed to be authored as a unit test

john
2021-11-30 08:43
so if i get rid of the mock server and stop it

john
2021-11-30 08:43
and then run it again i get this

john
2021-11-30 08:43
```with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" console.error Error: Error: connect ECONNREFUSED 127.0.0.1:9090```

john
2021-11-30 08:44
ah to be honest Matt they want us to learn to be devs i guess

matt.fellows
2021-11-30 08:45
Your API client needs to point at the port 3000 now, not 9090

matt.fellows
2021-11-30 08:45
Or change the mock service to start on 9090

john
2021-11-30 08:47
``` pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "9090" console.error Error: Error: Response for preflight has invalid HTTP status code 500```

john
2021-11-30 08:50
i can talk with the dev that helped me out earlier. I have a bit more informationnow

matt.fellows
2021-11-30 08:54
Might just need cors enabled

matt.fellows
2021-11-30 08:54
Can help tomorrow, kids dinner

john
2021-11-30 08:54
ah sure thanks for helping me out, is appreciated

tausif2909
2021-11-30 09:29
Well, I have pinned the version to `10.0.0-beta.20` on that build got passed, `ffi-napi` 's latest version was causing the issue I guess

tausif2909
2021-11-30 09:32
BTW, Do we have any timeline or expected date to release `PACT-V3` , Sometimes my PR reviewers hesitate to approve my PR when I use the beta version. my main purpose to use beta version is I require to use `providerState` thats not available in the official release.

tausif2909
2021-11-30 09:34
If possible please release `providerState` in stable version :slightly_smiling_face:

mfellows_20211130v2
2021-11-30 10:32
has joined #pact-js

tjones
2021-11-30 10:37
Put `cors: true` in your options in your `new Pact({...})` call

tjones
2021-11-30 10:38
> Response for preflight has invalid HTTP status code 500 ^ This means that the preflight (cors) request got a 500 response, which is what the mock does when you don't match the expectations it has. `cors: true` tells it to expect the cors preflight requests.

tjones
2021-11-30 10:38
Yes, this is a priority for the project

john
2021-11-30 10:45
ah yeah, i did do that earlier on

john
2021-11-30 10:45
im getting some weird application error now and a 500 status response so ill speak witht he dev tomorrow

john
2021-11-30 10:45
thanks Timothy

matt.fellows
2021-11-30 10:46
if you manually setup the mock service before and your code was passing, whatever flags you have the CLI mock server you need to replicate to your pact test

john
2021-11-30 10:48
yes ill need to delve into that

mfellows_20211130v3
2021-11-30 10:57
has joined #pact-js

mfellows_20211130v4
2021-11-30 11:16
has joined #pact-js

agittcelik
2021-11-30 18:35
has joined #pact-js

alturil
2021-11-30 20:56
has joined #pact-js

john
2021-12-01 05:39
so i tried again this afternoon. I spun up the mock server and. just pointed an insomnia graphql request at it and that works out of the box

john
2021-12-01 05:39
i tried to replicate that in that pact test, witht he same query and the same query variables but it doesnt work for some reason

tjones
2021-12-01 05:42
Could you share more details? How are you spinning up the mock server?

john
2021-12-01 05:43
no what i mean, i just wanted to see if the query works, so i started our mock server - nothing to do with pact and hit that local mock server with a graphql request and that all works

john
2021-12-01 05:44
in my test i dont have to start that mock server do i? Yesterday you said I should not do that that. That pact somehow starts its own mock server

tjones
2021-12-01 05:45
Right. In that case, what do you mean by "it doesn't work"?

john
2021-12-01 05:45
im getting a 500 server error

tjones
2021-12-01 05:45
You don't have to manually start the mock you do have to start the mock with `provider = new Pact()` and call `provider.setup()` and `provider.addInteraction()` on it

tjones
2021-12-01 05:46
500 can mean that the pact mock didn't get what it was expecting. You have to ensure that the request matches what is set up in the expectation

tjones
2021-12-01 05:46
there should be more information in the log file

tjones
2021-12-01 05:46
under `pact/log` or `log`, or wherever you configured it to be, depending on your setup

john
2021-12-01 05:47
int he log this is missing

john
2021-12-01 05:47
``` "path": "/api/v2/graphql", "query": "", "method": "post",```

john
2021-12-01 05:47
the query

john
2021-12-01 05:48
and this stuff

john
2021-12-01 05:48
[2021-12-01T15:41:55.474396 #84067] *ERROR* -- : No matching interaction found for POST /api/v2/graphql *E*, [2021-12-01T15:41:55.474408 #84067] *ERROR* -- : Interaction diffs for that route: *E*, [2021-12-01T15:41:55.474420 #84067] *ERROR* -- : W, [2021-12-01T15:41:55.501090 #84067] WARN -- : Verifying - actual interactions do not match expected interactions. Unexpected requests: POST /api/v2/graphql W, [2021-12-01T15:41:55.501133 #84067] WARN -- : Unexpected requests: POST /api/v2/graphql I, [2021-12-01T15:41:55.507248 #84067] INFO -- : Cleared interactions

tjones
2021-12-01 05:49
Ok, this says that it got an unexpected request. And, it doesn't list any expected request, so I think it's saying that the interaction wasn't set up

tjones
2021-12-01 05:49
Is your code still the same as above?

john
2021-12-01 05:50
```describe('GraphQL example', () => { // Explicit longer timeout to account for Pact server needing to spin up // Was throwing timeout errors after default 5 second timeout jest.setTimeout(30000) process.env.GRAPHQL_API_ENDPOINT = 'http://localhost:9090/api/v2/graphql' process.env.STAGE = 'local'; const provider = new Pact({ port: 9090, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), consumer: 'GraphQLConsumer', provider: 'GraphQLProvider', logLevel: 'debug', cors: true, timeout: 30000 }) beforeAll(() => provider.setup()) afterAll(() => provider.finalize()) describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `{ ProfileQuery { username } } ` ) .withOperation('ProfileQuery') .withRequest({ path: '/api/v2/graphql', method: 'POST' }) .withVariables({ "username": "default", }) .willRespondWith({ status: 200, body: { id:1, username: 'default' } }) return provider.addInteraction(graphqlQuery) }) }) it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {referrer: ""}) return expect(account).to.deep.contain({ username: 'default' }) }) afterEach(() => provider.verify()) })```

tjones
2021-12-01 05:52
Ok, the `it` block is not in the right place - it doesn't have the `beforeEach` that sets up the interaction

tjones
2021-12-01 05:52
move it to inside the describe: ``` describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `{ ProfileQuery { username } } ` ) .withOperation('ProfileQuery') .withRequest({ path: '/api/v2/graphql', method: 'POST' }) .withVariables({ "username": "default", }) .willRespondWith({ status: 200, body: { id:1, username: 'default' } }) return provider.addInteraction(graphqlQuery) }) it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {referrer: ""}) return expect(account).to.deep.contain({ username: 'default' }) }) })```

tjones
2021-12-01 05:53
Small irrelevant aside: I don't think `'query profile on /'` is the right name for that describe block, but that won't affect the test run

tjones
2021-12-01 05:56
You might be asking "how would I have known this?" - in the log file, you can see that the log is getting a request that it isn't expecting, but you can't see the setup of the interaction (or if you can, there will be a log entry that shows it is cleared before the test is run)

tjones
2021-12-01 05:56
Getting the lifecycle methods in order is kind of boilerplate, which is why we introduced jest-pact, which does everything except the `addInteraction` for you

tjones
2021-12-01 05:57
I'll quickly rewrite your test with jest-pact so you can see the difference and see if you like it


john
2021-12-01 05:57
do i need to add some dependency for that to work?

john
2021-12-01 05:58
this test is being run with jest

tjones
2021-12-01 05:59
```import { pactWith } from 'jest-pact'; pactWith( { port: 9090, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), consumer: 'GraphQLConsumer', provider: 'GraphQLProvider', logLevel: 'debug', cors: true, timeout: 30000, }, (provider) => { process.env.GRAPHQL_API_ENDPOINT = 'http://localhost:9090/api/v2/graphql'; process.env.STAGE = 'local'; describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `{ ProfileQuery { username } } ` ) .withOperation('ProfileQuery') .withRequest({ path: '/api/v2/graphql', method: 'POST', }) .withVariables({ username: 'default', }) .willRespondWith({ status: 200, body: { id: 1, username: 'default', }, }); return provider.addInteraction(graphqlQuery); }); it('returns the correct response', async () => { const { account } = await profilePageQuery('default', { referrer: '' }); return expect(account).to.deep.contain({ username: 'default' }); }); }); } );```

tjones
2021-12-01 05:59
yes, `npm install --save-dev jest-pact`


tjones
2021-12-01 06:01
(you don't *need* to use it, but it will mean that you don't have to have the setup/verify/finalise calls)

tjones
2021-12-01 06:03
Also, if you omit the `log` and `dir` options, it gives you some nice defaults: https://github.com/pact-foundation/jest-pact#defaults

tjones
2021-12-01 06:10
Did your test pass once you moved the `it` block?

john
2021-12-01 06:10
so Timothy

john
2021-12-01 06:10
im getting a little further so thanks

john
2021-12-01 06:11
i think maybe the issue before was in the willRespondWith block

john
2021-12-01 06:11
i only but a small part of it in there

john
2021-12-01 06:11
so maybe that was screwing it up?

tjones
2021-12-01 06:12
You need to have the full response that your consumer requires in there

john
2021-12-01 06:12
im getting this now in the log file

john
2021-12-01 06:12
Description of differences --------------------------------------

john
2021-12-01 06:12
i just dumnped the response from insomnia in there

john
2021-12-01 06:13
the response i got from our own mock server

john
2021-12-01 06:13
so i wouldnt expect there to be differences ill need to take a closer look i guess

john
2021-12-01 06:22
thanks Timothy you. really helped a lot

tjones
2021-12-01 06:23
You're welcome. The graph-ql matcher is a bit strict about the spacing etc (it's backed by a regex) so you may want to look there

john
2021-12-01 06:24
is that why i get issues like this:

john
2021-12-01 06:24
```- "query": /\{\s*ProfileQuery\s*\{\s*username\s*\}\s*\}\s*/, + "query": "query ProfileQuery(\n $username: String!\n```


tjones
2021-12-01 06:25
that's a full no-match

john
2021-12-01 06:26
yeah it said the request body didnt match

tjones
2021-12-01 06:27
your expected request looks like `{ ProfileQuery ....`, but your actual request looks like `query ProfileQuery( ...`

john
2021-12-01 06:27
ill fiddle with that to see if i can fix that

draper.joseph
2021-12-01 06:50
has joined #pact-js

abhay175
2021-12-01 07:35
has joined #pact-js

joelgrimberg
2021-12-01 11:27
has joined #pact-js

reem.alashry
2021-12-01 12:09
has joined #pact-js

beshoy.ibrahim
2021-12-01 12:09
has joined #pact-js

omar.radi
2021-12-01 12:10
has joined #pact-js

mmudassar192
2021-12-01 12:11
has joined #pact-js

ozgurerisir
2021-12-01 13:22
Hi All, struggling with Publishing my contract to Pact broker. Keep getting this error, any ideas? throw new Error("Path '" + v + "' given in pactFilesOrDirs does not exists.");

eric.seipold
2021-12-01 13:40
has joined #pact-js

matt.fellows
2021-12-01 13:43
How are you publishing?

matt.fellows
2021-12-01 13:43
Can you please provide some more info, that doesn't look like an error our code throws

ozgurerisir
2021-12-01 14:23
I've downloaded an example from PactFlow. It populated my Pact broker url and token and Im using 'npm test' to run the tests. It says the test will need to pass, which will then create the contract file before I can publish using, npm run test:publish. Before I run tests do I need to change anything in test/publish.js?

ozgurerisir
2021-12-01 14:23
Error I get is this: ? npm test > syndication-mocha-example@1.0.0 test > rimraf pacts && mocha [2021-12-01 14:19:34.470 +0000] INFO (x on x): pact-node@10.15.0: Publishing Pacts to Broker C:\Users\x\Downloads\syndication-javascript-node-consumer-mocha\node_modules\@pact-foundation\pact-node\src\publisher.js:37 throw new Error("Path '" + v + "' given in pactFilesOrDirs does not exists."); ^ Error: Path 'C:\Users\x\syndication-javascript-node-consumer-mocha\pacts' given in pactFilesOrDirs does not exists. at C:\Users\x\syndication-javascript-node-consumer-mocha\node_modules\@pact-foundation\pact-node\src\publisher.js:37:27 at Array.map (<anonymous>)

amiller
2021-12-01 16:27
Hey there team, I hope all is well. I have a quick question. Does the pact-js binding allow for decoupling of the mock service provider. i.e., having a consumer test written in typescript, and having the mock provider service up through docker My ask is similar to this github issue: https://github.com/pact-foundation/pact-php/issues/152 Please let me know and thanks!

leonardo.viana
2021-12-01 16:29
@tjones, could you please take a look at my question above regarding the timeframe for nodejs 16 support?

apselsevier
2021-12-01 16:48
has joined #pact-js

ali.korayem
2021-12-01 18:55
has joined #pact-js

luiz.filipe.abrahao
2021-12-01 21:04
has joined #pact-js

tjones
2021-12-01 22:01
You _can_ do this, but in general it is better practice not to - what is the reason you want to do this?

tjones
2021-12-01 22:02
I'm afraid I don't have a time frame. This is an open source project, supported in the spare time of the maintainers.

amiller
2021-12-01 22:05
My team is running docker node alpine which doesn't have some key dependencies needed for the pact mock provider to function properly. Mainly the missing ruby binary

tjones
2021-12-01 22:05
You don't need the ruby binary

tjones
2021-12-01 22:06
If you're running docker alpine, it is missing bash, which is required for the ruby standalone (which is the thing that means you don't need the ruby binary)

tjones
2021-12-01 22:06
usually people just add bash to alpine to get around this

tjones
2021-12-01 22:07
If you want to manage your own mock service, then you'll have to reimplement a lot of the lifecycle management, and I think you'll generally have a bad experience

tjones
2021-12-01 22:08
it is possible, though. This is how pact-web works, which is what people who are running all their tests through a browser use

amiller
2021-12-01 22:09
Ah I see. I'll take a look at our options with regards to baking bash into that alpine image. Thanks @tjones!

tjones
2021-12-01 22:10
You only need pact at test time, so if image size is a concern (which I think is usually the driver for alpine), then I'd recommend having a separate image for testing

tjones
2021-12-01 22:10
also I don't think bash changes the size very much, but don't quote me on that

amiller
2021-12-01 22:11
Ah good point, I could go that route as well

amiller
2021-12-01 22:11
With the separate image

tjones
2021-12-01 22:27
If you're still getting errors on alpine after installing bash, something is not right. It should work then

tjones
2021-12-01 22:36
If you're interested, this is what is currently blocking it: https://github.com/node-ffi-napi/ref-napi/pull/64

tjones
2021-12-01 22:39
Basically, the problem is native bindings from node. We're using the most popular wrapper for node's native API (NAPI) - which is `node-ffi-napi`. This means that we can call native libraries (such as the new Rust core for Pact) without needing to write C code to translate between the JS and the core library. However, `node-ffi-napi` has a bug that affects node 14+, appears not to be actively maintained, and I don't understand the fix well enough to address the comments on the PR.

tjones
2021-12-01 22:40
The two "easiest" options for getting a fix out asap are: 1) Understand that fix and fix it 2) Write our own C wrapper for NAPI Unfortunately, I don't have the time to make a serious dent in either.

tjones
2021-12-01 22:41
This problem affects anyone wanting to do native bindings from node, so I imagine some package will come along that *is* maintained and works on node 14+

tjones
2021-12-01 22:41
(the risk with option 2 above is that maybe we'd now be maintaining that package too, which isn't ideal)

matt.fellows
2021-12-02 00:18
see also https://docs.pact.io/docker/ (not just bash)

tjones
2021-12-02 01:10
huh, interesting. I've never had to install anything else, but perhaps the images I was using already had those other dependencies

matt.fellows
2021-12-02 01:11
yeah. the answer is usually ?it depends? but those 3 dependencies cover all of the scenarios i?ve seen.

john
2021-12-02 01:23
ok i got the consumer test working,

john
2021-12-02 01:24
next drama will be to get the provider working with PHP_ lol

tjones
2021-12-02 01:36
Glad to hear it!

john
2021-12-02 02:39
so how does pact work along something like hive which does graphql schema checking in the cicd pipeline?

tjones
2021-12-02 04:45
I don't know hive, but schema checking checks grammar, while pact checks by example

tjones
2021-12-02 04:46
a schema-compliant message may not have meaning

tjones
2021-12-02 04:46
but test-by-example confirms that you can understand the actual response that is generated

tjones
2021-12-02 04:47
in English, "colourless green ideas sleep furiously" is grammatically correct, but doesn't mean anything

tjones
2021-12-02 04:47
Schema testing is good if you don't have the ability to do anything else; it's better than nothing

tjones
2021-12-02 04:47
but pact (and contract testing in general) with examples is much better for giving confidence that your tests are correct

akanksha.sharma
2021-12-02 11:27
Hi @matt.fellows, as Murali discussed with you on call about producer driven contract testing, did you guys release something in Pact itself which supports producer driven contract testing.

matt.fellows
2021-12-02 11:29
Hi Akanksha, no the feature discussed on the call is a Pactflow specific feature

matt.fellows
2021-12-02 11:29
On the provider side, you upload the OAS file to Pactflow (and your job is to ensure that the OAS is correct, and that the provider is compatible with it. This could be a series of Postman tests, or an autogenerated OAS from code)

matt.fellows
2021-12-02 11:30
On the consumer side, you can still use Pact to generate a consumer contract (there is both a consumer _and_ provider contract). If you don?t use Pact, you can use whatever other mocking tool you like, as long as you can convert them into a pact file

matt.fellows
2021-12-02 11:30
See the examples and how to do that here: https://docs.pactflow.io/docs/workshops/bi-directional

david.cummings
2021-12-02 14:13
has joined #pact-js

miccagiann
2021-12-02 14:17
has joined #pact-js

praveen.em
2021-12-03 07:40
has joined #pact-js

ally.parker
2021-12-03 11:18
has joined #pact-js

rishabh.gaur
2021-12-03 11:43
has joined #pact-js

william.wallace
2021-12-03 15:12
has joined #pact-js

batiushkov.nik
2021-12-03 15:48
has joined #pact-js

keith.mcgrath
2021-12-03 18:28
has joined #pact-js

rchandragupthara
2021-12-03 19:32
has joined #pact-js

rchandragupthara
2021-12-03 19:34
when i run publish from local - terminal the pact is tagged with the correct branch name , but when i run the same branch from CI it gets tagged as HEAD (in this case dev is our main branch) ```pact-broker publish ./pacts/*.json --consumer-app-version=\"$(git rev-parse --short HEAD)\" --tag=\"$(git rev-parse --abbrev-ref HEAD)\"```

mike.geeves064
2021-12-03 19:43
Have you verified the git commands are actually coming back with what you expect? I've had weirdness (on GitLab for me) due to it not by default pulling a full clone, only partial (shallow)

rchandragupthara
2021-12-03 19:48
yes.. it is correct.. well atleast it works for me locally from my terminal.. The git commit it gets tagged with on the pact-broker are also correct both from my local and from CI .

mike.geeves064
2021-12-03 19:49
yeah that's what I meant, difference of how it is with a full clone locally and a shallow clone that was pulled for CI

mike.geeves064
2021-12-03 19:49
so just e.g. echo'ing out those git commands as a CI step gives the expected output?

mike.geeves064
2021-12-03 19:54
For me, the problem was GitLab wasn't pulling down tags for the repo, only the relevant commit. My use case was to pull out the most recent x.y.z tag so I could then build x.<y+1>.0-<commit hash> tagged versions without manual numbering. May be something completely different but worth verifying your CI does have all the info you expect


rchandragupthara
2021-12-03 19:56
just checked its. a full clone.. And the CI's internal (default ) git variables are correct. commit / brnach name I am fairly new to these git commands that i have put in the package.json's script for pact-publish/ can-i-deploy..

mike.geeves064
2021-12-03 19:57
hmm

mike.geeves064
2021-12-03 19:57
nvm with that one then :slightly_smiling_face:

rchandragupthara
2021-12-03 19:58
so so same commit ID on the same brnach.. ran from local --> gets tagged as 'dev' as expected ran from CI ( same commit / branch) --> gets tagged as HEAD

vinicius.cosmi
2021-12-03 20:01
has joined #pact-js

mike.geeves064
2021-12-03 20:04
hmm

mike.geeves064
2021-12-03 20:04
Jenkins?


rchandragupthara
2021-12-03 20:17
trying this.. will keep u posted.. thanks!

rchandragupthara
2021-12-03 20:22
dammmm... It worked .. thanks so much

mike.geeves064
2021-12-03 20:24
Awesome, you're welcome :grinning:

matt.fellows
2021-12-03 21:05
:taco: for @mike.geeves064 - thanks!

mike.geeves064
2021-12-03 21:09
:party_parrot:

ichatterjee
2021-12-03 21:27
has joined #pact-js

mike.geeves064
2021-12-03 21:29
:thinking_face: I don't think I've come across Pact CI examples for the versions, fixed numbers or "you should use something like the git sha", but not CI specific.. one for the Todo list maybe?

ben.watts
2021-12-03 23:48
has joined #pact-js

imikhtyuk
2021-12-06 00:36
has joined #pact-js

john
2021-12-06 03:36
Just another quick question about the provider side of things. I see int he example that you for example import an app (express app) in the consumer test and use that as the basis of the provider test. ```describe("Pact Verification", () => { before(done => { server = app.listen(4000, () => { done() }) })```

john
2021-12-06 03:37
and here: ```providerBaseUrl: "http://localhost:4000/graphql",``` can i just point my provider test to some qa mesh qraphql endpoint instead of importing it?

tjones
2021-12-06 03:39
The express server is only imported in the provider verification, I think?

tjones
2021-12-06 03:39
yes, you can

tjones
2021-12-06 03:39
However, the reason you might not want to, is that the hooks for state change are easier to use if the app is running locally

tjones
2021-12-06 03:40
for example, you can use dependency injection to modify a repository mock inside the app

tjones
2021-12-06 03:40
but if you don't need that, there's no reason not to start the server independently

john
2021-12-06 03:42
sorry i dont know why i said consumer test, i meant provider

john
2021-12-06 03:43
so i could ditch that before block and just point the baseUrl to that qa endpoint?

tjones
2021-12-06 03:44
(in fact, if you're just pointing at a running server, you don't need to use the same pact framework - you can use JS to test a Java app, etc etc)


tjones
2021-12-06 03:44
In that case, yes! What you've said is right.

john
2021-12-06 03:45
what do you mean dont need to use the same pact framework?

john
2021-12-06 03:45
can u elaborate

john
2021-12-06 03:47
i thought maybe just to change this: ```it("validates the expectations of Matching Service", () => { // lexical binding required here const opts = { // Local pacts // pactUrls: [path.resolve(process.cwd(), "./pacts/graphqlconsumer-graphqlprovider.json")], pactBrokerPassword: "O5AIZWxelWbLvqMdh2Psyg1", pactBrokerUrl: "https://test.pact.dius.com.au/", pactBrokerUsername: "dXfltyFMgN9wJ37iUpY42M", provider: "GraphQLProvider", providerBaseUrl: "http://qa_graphql_server/graphql", providerVersion: versionFromGitTag(), publishVerificationResult: true, consumerVersionTags: ["master", "test", "prod"], } return new Verifier(opts).verifyProvider()```

john
2021-12-06 03:58
so it is better practise to spin up the real server locally

matt.fellows
2021-12-06 04:27
I think Tim means that you don?t necessarily need to use Pact JS to test a JS *provider* application running on an external server, because you?re not really using any JS code

matt.fellows
2021-12-06 04:28
i.e. you could use the CLI verifier, or any other language you find better suited to the task. The main reason to use the language specific binding, is so that you can take advantage of mocking/stubbing tools and other techniques readily available to a unit testing framework. If you?re pointing at an end-to-end environment / staging environment, these tools aren?t going to be very helpful (i.e. you can?t remote stub)

john
2021-12-06 04:42
i see. I have access to the php graphql repo so it make sense for demo purposes to just use that instead of some server running on a qa env right? Ive never used php beforer so im just trying to learn how to import the server into the test, like you do witht he js example.

matt.fellows
2021-12-06 05:54
Kudos for your persistence!

norrischebl
2021-12-06 05:54
has joined #pact-js

tjones
2021-12-06 06:15
> im just trying to learn how to import the server into the test, You'll have a hard time importing the server into the JS test (maybe you could with pact PHP). As Matt says, you only need to do this if you want to use your testing framework to do stubbing for provider states.

tjones
2021-12-06 06:15
Otherwise, just point it at your server and you're good to go

tjones
2021-12-06 06:15
(I used to only ever spin up the server separately, you can definitely go that route)

smantini
2021-12-06 09:25
has joined #pact-js

gzinger
2021-12-06 11:19
has joined #pact-js

mahatmafatal
2021-12-06 13:50
has joined #pact-js

jacob.v.gardner
2021-12-06 14:59
has joined #pact-js

william.wallace
2021-12-06 16:31
Hello, just getting started with pact and typescript. I don't see a separate typescript channel, so I'm assuming this is the place for typescript questions. I'm running this example: https://github.com/pact-foundation/pact-js/tree/master/examples/typescript On master with no changes, when I run `npx tsc` I see errors. I'm assuming this should work, but it doesn't. Perhaps I'm doing something wrong? ```$ npx tsc Debugger listening on For help, see: https://nodejs.org/en/docs/inspector Debugger attached. Debugger listening on For help, see: https://nodejs.org/en/docs/inspector Debugger attached. node_modules/@types/sinon-chai/index.d.ts:107:31 - error TS2694: Namespace 'Chai' has no exported member 'ChaiPlugin'. 107 declare const sinonChai: Chai.ChaiPlugin; ~~~~~~~~~~ Found 2 errors.```

matt.fellows
2021-12-06 23:09
Why are you compiling the typescript? It?s really just a test fixture to illuminate how to run a pact test

matt.fellows
2021-12-06 23:09
you just need to run `npm t`

matt.fellows
2021-12-06 23:10
that being said, I?m sure the config could do with some updates. It looks like it complains about dependencies types

tjones
2021-12-07 02:19
It shouldn't be compiling the dependencies

tjones
2021-12-07 02:20
Possibly the tsconfig is incorrect

tjones
2021-12-07 02:20
Anyway, `npx tsc` is definitely not going to work - where is that specified in the documentation? We should correct it.

glebing2000
2021-12-07 07:28
has joined #pact-js

akanksha.sharma
2021-12-07 08:56
Can someone please share an example for Post API contract test

akanksha.sharma
2021-12-07 08:58
This is my consumer test ```"use strict" const { Matchers } = require("@pact-foundation/pact") const { postClient, getClient } = require("../../../src/consumer") describe("Clients Service", () => {     const GET_EXPECTED_BODY = {         accountId: 9348878860,          agencyCode: "4218",          accountStatus: "Open"       }     afterEach(() => provider.verify())     describe("GET Clients", () => {         beforeEach(() => {             const interaction = {                 state: "i have an account",                 uponReceiving: "a request for the account Api",                 withRequest: {                     method: "GET",                     path: "/v1/accounts/9348878860",                     headers: {                         Accept: "application/json, text/plain, */*",                     },                 },                 willRespondWith: {                     status: 200,                     headers: {                         "Content-Type": "application/json; charset=utf-8",                     },                     body: GET_EXPECTED_BODY,                 },             }             return provider.addInteraction(interaction)         })         test("returns correct body, header and statusCode", async() => {             const response = await getClient(9348878860)             expect(response.headers['content-type']).toBe("application/json; charset=utf-8")             expect(response.data).toEqual(GET_EXPECTED_BODY)             expect(response.status).toEqual(200)         })     })     const POST_BODY = {         "isExpanded":false,         "showMore":false,         "isSelected":false,         "displayCommentBox":false,         "displayActivityDropdown":false,         "isReferralEditing":false,         "datePipe":{            "locale":"en-US"         },         "activityType":"Note",         "activityDtTm":"2021-12-01T16:28:31.000Z",         "note":{            "isEditing":false,            "datePipe":{               "locale":"en-US"            },            "isEdited":false,            "editedDate":null,            "editedTime":null,            "notes":"<p>test pact</p>"         },         "contacts":[                     ],         "activityFlag":"Normal",         "dueDate":null,         "sendTo":"Services"     }     const POST_EXPECTED_BODY = {         activityType: POST_BODY.activityType,         //activityDtTm: POST_BODY.activityDtTm,         activityFlag: POST_BODY.activityFlag,         //sendTo: POST_BODY.sendTo,         //isEditing: POST_BODY.note.isEditing,         //locale: POST_BODY.datePipe.locale,         //notes: POST_BODY.note.notes     }     describe("Post Client", () => {                  beforeEach(() => {             const interaction = {                 state: "i share a new note",                 uponReceiving: "a request to create a new note",                 withRequest: {                     method: "POST",                     path: "/v1/accounts/9404268316/user_activities/notes",                     headers: {                         "Content-Type": "application/json;charset=utf-8"                     },                     body: POST_BODY,                 },                 willRespondWith: {                     status: 200,                     body: Matchers.like(POST_EXPECTED_BODY).contents,                     //body: POST_EXPECTED_BODY,                 },             }             return provider.addInteraction(interaction)         })         test("returns correct body, header and statusCode for Post Api", async() => {             const response = await postClient(POST_BODY)             console.log("Response is : " + response.data)             //expect(response.data.activityFlag).toEqual('Normal')             expect(response.status).toEqual(200)     })   }) })```

akanksha.sharma
2021-12-07 08:58
my test is getting failed at this point in Post API

tjones
2021-12-07 09:32
This error looks like it is because your code is not returning what you are expecting it to

tjones
2021-12-07 09:33
Also, it looks like the actual post request (if any) didn't match the request you set up

tjones
2021-12-07 09:33
Have a look in the log file to see what happened

tjones
2021-12-07 09:33
(there should be a note to do that in the log you shared - either above or below your screenshot)

matt.fellows
2021-12-07 09:47
yes, the reason for the failure is notably absent there

matt.fellows
2021-12-07 09:48
It should tell you which request it was expecting, and what it received. The log file as Tim mentioned will tell you this

matt.fellows
2021-12-07 09:48
To answer your question though, there is a POST example in the e2e examples in the Pact JS repository

sergio.freire
2021-12-07 09:52
has joined #pact-js

akanksha.sharma
2021-12-07 10:14
Okay

matt.fellows
2021-12-07 10:20
If I were to have a guess, it?s that your `await postClient(POST_BODY)` doesn?t know to send it to account with id `9404268316` (I can?t see how it would know that from the context). But you?ll need to log in your terminal/logs to see what your actual code is doing

sahoo.skumar
2021-12-07 10:55
has joined #pact-js

akanksha.sharma
2021-12-07 11:39
Yeah, its actually throwing this error

akanksha.sharma
2021-12-07 11:39
something like missing request

akanksha.sharma
2021-12-07 11:40
```const postClient = async (body) => {       const res = await axios       .post(`${getApiEndpoint}}/v1/accounts/9404268316/user_activities/notes`, body, {'Content-Type': 'application/json;charset=utf-8'})       .then((res) => {           return res         })         .catch((err) => {           return err.res         })     return res }```

akanksha.sharma
2021-12-07 11:41
this is my postClient method

akanksha.sharma
2021-12-07 11:41
Here I have given the end point of the API which includes the account Id as well

matt.fellows
2021-12-07 12:48
Is the request being sent to them pact mock server or the talk API? It needs to point at the mock server created by pact

matt.fellows
2021-12-07 12:48
Check out the pact log file, it will tell you what it sees


william.wallace
2021-12-07 13:07
Thank you for all your responses. If I make changes to the `get-dog.spec.ts` and `index.ts`, I assume that that I would need to run `npm tsc` to rebuild. Perhaps I'm wrong? The reason I started down that path is that it seemed that my changes to the tests and `index.ts` were not getting evaluated. I then reverted all my changes and ran `npm tsc` and noticed the dependency error with `sinon-chai` persisted. The `npm t` command runs the test as expected, and succeeds when there are no changes. This command fails when I change the tests, but when run in a dubugger, the code with my changes cannot be stepped into. In any case, please clarify when compiling is necessary.

kingyang728
2021-12-07 15:58
has joined #pact-js

jesseaantebi
2021-12-07 19:36
has joined #pact-js

rsheikh
2021-12-07 22:34
has joined #pact-js

matt.fellows
2021-12-08 00:56
You shouldn?t need to run tsc at all

matt.fellows
2021-12-08 00:57
The mocha config is setup to automagically interpret the typescript as part of running the test: ```--bail --require ts-node/register --require ./test/helper.ts --require source-map-support/register --full-trace --reporter spec --colors --recursive --timeout 30000 test/*.spec.ts```

matt.fellows
2021-12-08 00:57
I?ve just changed both the spec and the `index.ts` , and the changes are picked up without needing to run anythnig else other than `npm t`

matt.fellows
2021-12-08 00:58
i.e. if I update `index.ts` to hit a different, unexpected endpoint I get this: ```... The Dog API [2021-12-08 00:58:38.232 +0000] INFO (71938 on Matts-iMac): pact-node@10.13.3: Pact running on port 59449 [2021-12-08 00:58:38.641 +0000] INFO (71938 on Matts-iMac): pact@9.16.0: Setting up Pact with Consumer "Typescript Consumer Example" and Provider "Typescript Provider Example" using mock service on Port: "59449" get /dogs using builder pattern 1) returns the correct response Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /dogs Unexpected requests: GET /iupdatedindex.ts See /Users/matthewfellows/development/public/pact-js/examples/typescript/logs/mockserver-integration.log for details. 2) "after each" hook for "returns the correct response" [2021-12-08 00:58:38.684 +0000] INFO (71938 on Matts-iMac): pact@9.16.0: Pact File Written [2021-12-08 00:58:38.684 +0000] INFO (71938 on Matts-iMac): pact-node@10.13.3: Removing Pact process with PID: 71939 [2021-12-08 00:58:38.687 +0000] INFO (71938 on Matts-iMac): pact-node@10.13.3: Deleting Pact Server with options: {"consumer":"Typescript Consumer Example","cors":false,"dir":"/Users/matthewfellows/development/public/pact-js/examples/typescript/pacts","host":"127.0.0.1","log":"/Users/matthewfellows/development/public/pact-js/examples/typescript/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":59449,"provider":"Typescript Provider Example","spec":2,"ssl":false}```

matt.fellows
2021-12-08 00:59
If I updated the spec to expect a different path: ```... The Dog API [2021-12-08 00:59:15.554 +0000] INFO (72018 on Matts-iMac): pact-node@10.13.3: Pact running on port 59463 [2021-12-08 00:59:15.947 +0000] INFO (72018 on Matts-iMac): pact@9.16.0: Setting up Pact with Consumer "Typescript Consumer Example" and Provider "Typescript Provider Example" using mock service on Port: "59463" get /dogs using builder pattern 1) returns the correct response Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /iexpectadifferentendpoint Unexpected requests: GET /dogs See /Users/matthewfellows/development/public/pact-js/examples/typescript/logs/mockserver-integration.log for details.```

matt.fellows
2021-12-08 00:59
all I?m runnig is `npm t`. I think the documentation is correct from what I can see

jorgwel
2021-12-08 01:22
has joined #pact-js

rahul.anwekar23
2021-12-08 04:19
has joined #pact-js

luanacosta05
2021-12-08 20:34
has joined #pact-js

tjones
2021-12-09 00:20
How are you running the debugger?

tjones
2021-12-09 00:20
What do you mean by ?cannot be stepped into? - can you tell us what error you are getting? I think this is probably a config issue with your typescript setup, which means it might be hard for us to help.

saurabh.techiee
2021-12-09 09:41
has joined #pact-js

albertcabantog
2021-12-09 10:52
has joined #pact-js

paul.scholes
2021-12-10 10:21
has joined #pact-js

paul.scholes
2021-12-10 10:25
Hi All, I am trying pact for the first time, and I have got as far as running my provider test, but I am getting a connection refused from the localhost. Provider test: ```const { Verifier } = require('@pact-foundation/pact'); describe('Login verification', () => { jest.setTimeout(60000); test('Validate ACD Login', () => { let opts = { provider: 'loginAPI', providerBaseUrl: 'http://localhost:8800', pactBrokerUrl : '########', pactBrokerToken: '#######', providerVersion: '1.0.0', logLevel: 'DEBUG' } return new Verifier(opts).verifyProvider(); }) })``` The log (once the pact file has been retreived: `Verifying a pact between loginService and loginAPI [PENDING]` `A valid auth request` `with POST /api/login` `[2021-12-10 09:59:46.884 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: returns a response which` `[2021-12-10 09:59:46.884 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0:` `[2021-12-10 09:59:46.886 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: DEBUG: Setting up provider state '' for consumer 'loginService' using provider state set up URL http://localhost:57035/_pactSetup` `[2021-12-10 09:59:46.908 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: I, [2021-12-10T09:59:46.907242 #12864] INFO -- request: POST http://localhost:57035/_pactSetup` `[2021-12-10 09:59:46.910 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: D, [2021-12-10T09:59:46.908239 #12864] DEBUG -- request: User-Agent: "Faraday v0.17.4"` `Content-Type: "application/json"` `[2021-12-10 09:59:46.971 +0000] WARN (171912 on DESKTOP-9AIJ0DN): pact@9.17.0: No state handler found for "null", ignoring` `[2021-12-10 09:59:46.983 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: I, [2021-12-10T09:59:46.982739 #12864] INFO -- response: Status 200` `[2021-12-10 09:59:46.983 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: D, [2021-12-10T09:59:46.982739 #12864] DEBUG -- response: x-powered-by: "Express"` `content-type: "text/plain; charset=utf-8"` `content-length: "2"` `etag: "W/\"2-nOO9QiTIwXgNtWtBJezz8kv3SLc\""` `date: "Fri, 10 Dec 2021 09:59:46 GMT"` `connection: "close"` `[2021-12-10 09:59:47.014 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact@9.17.0: Proxing` `Error: connect ECONNREFUSED 127.0.0.1:8800` `at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)` Can anyone help?

chris.sloan
2021-12-10 10:48
has joined #pact-js

matt.fellows
2021-12-10 11:01
Provider verification takes a contract file and checks if your provider is compatible with it by issuing HTTP calls to it. Have you started the provider? It seems you're probably not

matt.fellows
2021-12-10 11:02
Howtolearn

2021-12-10 11:02
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-12-10 11:02
You might like these tutorials too: https://docs.pactflow.io/docs/tutorials

paul.scholes
2021-12-10 11:04
Thanks @matt.fellows.

leon.york
2021-12-10 12:42
has joined #pact-js

yousafn
2021-12-10 14:29
I would agree that it looks like the provider isn?t started, or isn?t on port 8800. This is the bit of the log that gives me that information > `Error: connect ECONNREFUSED 127.0.0.1:8800` You could try and hit your provider via the command line, if it is started. looking at your request, its a post to `/api/login`, I?ve guessed the payload. ```curl -X http://127.0.0.1:8800/api/login -d '{"user":"foo","password":"bar"}'``` It is usually preferred to start your provider as part of the verifier step, so normally importing say the express or koa app and calling app.listen() on it, and tearing it down at the end. That way you can directly manipulate your provider, in order to set up appropriate state (test data) for state handlers

yousafn
2021-12-10 14:30
double post

kyle.craviotto
2021-12-10 16:40
has joined #pact-js

lorenz.schumann
2021-12-10 18:33
has joined #pact-js

william.wallace
2021-12-10 19:21
Thank you Matt! I didn't understand how/if typescript was handled by `npm t`. Knowing this is helpful: "The mocha config is setup to automagically interpret the typescript as part of running the test"

william.wallace
2021-12-10 19:49
To follow up on the typescript example issue, I found that mocha requires more arguments to be able to run mocha with typescript. This isn't so much a problem with the example, but when I implemented the example technique to run pact consumer tests against my typescript code, I was seeing an error: ```SyntaxError: Cannot use import statement outside a module``` To fix this, I added `mocha -r ts-node/register` to my `test` command under scripts in package.json: ```"scripts": { "test": "nyc --check-coverage --reporter=html --reporter=text-summary mocha -r ts-node/register test/*.spec.ts", "mocha:direct": "mocha" },``` https://chiragrupani.medium.com/writing-unit-tests-in-typescript-d4719b8a0a40

luispires.m
2021-12-13 12:32
has joined #pact-js

fabio.rodrigues
2021-12-13 16:22
has joined #pact-js

william.wallace
2021-12-13 20:09
Hello everyone, I'm using typescript to test an API, and I want to validate a 400 error code from the server. The typescript example uses this construct to run and validate successful responses, but how can I validate an error? ```it("returns the correct response", done => { dogService.getMeDogs().then((response: any) => { expect(response.data[0]).to.deep.eq(dogExample) done() }, done) })``` I've tried this, which ends up writing the proper entry into my pact, but the test fails ```it("should return 400", done => { try { dogService.getMeDogs().then((response: any) => { done() }, done) } catch(err: any) { console.log(`response: ${JSON.stringify(err.response.data[0])}`) // expect(err.response.data[0]).to.deep.eq(ERROR_400) } })``` Any ideas?

william.wallace
2021-12-13 20:55
I have some success with this construct. Curious if this is the best way to obtain non-200 responses for validation: ```it("should return 400", done => { dogService.getMeDogs().catch(function (error) { if(error.response) { console.log(`error data: ${error.response.data}`) console.log(`error status: ${error.response.status}`) console.log(`error headers: ${error.response.headers}`) } done() }) })```

tjones
2021-12-13 21:11
With jest, I do something like: ``` expect(dogService.getMeDogs()).rejects.toEqual( new SomeCustomError("Whatever the error is"), ));```

tjones
2021-12-13 21:11
There's nothing special about error handling with Typescript, just do the same as you would in JS

tjones
2021-12-13 21:12
you're (probably) testing for a failed promise

tjones
2021-12-13 21:13
In this part of the test, you're just testing that the business logic that is coming out of the API is correct - if your app returns a failed promise with a business error, assert against that. If your app returns an empty or an "API error" payload, assert against that

tjones
2021-12-13 21:14
This is a design comment, not a testing comment, but: ```dogService.getMeDogs().catch(function (error) { if(error.response) { console.log(`error data: ${error.response.data}`)``` ^ This doesn't feel right to me, because the http error response object belongs to the API layer. I think the API layer shouldn't expose this detail to the caller

william.wallace
2021-12-13 21:15
Thanks for the examples! Right - it's my newbness to JS /async constructs that's holding me back. I'm asserting against the body in the error, as that needs to contain specific fields.

tjones
2021-12-13 21:15
(I get around this by marshalling to custom errors or types in the API layer)

tjones
2021-12-13 21:15
right, but (in my opinion) the caller shouldn't know what the structure of the body is

tjones
2021-12-13 21:16
it should know what the structure of your error response type is. Maybe that's the same as the HTTP error, but if it is, I think you'll be leaking concerns

tjones
2021-12-13 21:16
eg, in your example, your caller might need to know what `status: 404` means, which doesn't feel right to me

yousafn
2021-12-13 21:16
Assuming you are talking about this test https://github.com/pact-foundation/pact-js/blob/master/examples/typescript/test/get-dog.spec.ts For that test ``` describe("get /dogs returns a 400", () => { before(() => { const interaction = new Interaction() .given("I have no dogs") .uponReceiving("a request for all dogs with the builder pattern") .withRequest({ method: "GET", path: "/dogs", headers: { Accept: "application/json", }, }) .willRespondWith({ status: 400, headers: { "Content-Type": "application/json", }, }) return provider.addInteraction(interaction) }) it("returns the correct response", done => { dogService.getMeDogs().catch((error)=>{ expect(error.status).to.eq(400) done() }) }) })```

tjones
2021-12-13 21:17
Oh right, the example follows the design I am advising against. We should fix that :wink:

yousafn
2021-12-13 21:17
You basically need to catch the error, assert in there, and then call done. (with mocha)

yousafn
2021-12-13 21:17
Yeah that pattern sucks tho

tjones
2021-12-13 21:17
Here's an example from my actual code: ``` expect(client.deleteAttachment(3)).rejects.toEqual( new NotFoundError("Attachment '3' not found"), ));```


tjones
2021-12-13 21:19
Here's (part) of the error handler that lives inside the API layer to support that code: ```const errorHandler = <T>( error: AxiosError<ServerError | ServerFatalError>, ): never => { if (axios.isAxiosError(error) && error.response) { // Marshal expected errors here if (error.response.status === 404 && error.response.data.description) { throw new NotFoundError(error.response.data.description); }```

william.wallace
2021-12-13 21:21
Thank you for the examples!

tjones
2021-12-13 21:21
To summarise: ? Yes, however your testing framework checks against rejected promises is what you want to do here (assuming your API layer returns a rejected promise when there's a 4xx or 5xx) ? It's best practice not to expose implementation details of the API layer to the caller

william.wallace
2021-12-13 21:23
Very good points, and an angle I hadn't considered. Thank you very much

tjones
2021-12-13 21:24
I prefer the explicit "I want this promise to resolve in this way" style, but if you want to use the `done` callback in mocha you could do something like this: ```it("should return 400", done => { dogService.getMeDogs().then(function() { done(new Error("This promise is not expected to resolve")) }, function (error) { if(error.response) { // Replace these with assertions on the data console.log(`error data: ${error.response.data}`) console.log(`error status: ${error.response.status}`) console.log(`error headers: ${error.response.headers}`) } done() }) })```

tjones
2021-12-13 21:25
or I think you can just return the promise - equivalent code: ```it("should return 400", () => { // Note the use of `return` here return dogService.getMeDogs().then(function() { throw new Error("This promise is not expected to resolve") }, function (error) { if(error.response) { // Replace these with assertions on the data console.log(`error data: ${error.response.data}`) console.log(`error status: ${error.response.status}`) console.log(`error headers: ${error.response.headers}`) } }) })```

tjones
2021-12-13 21:26
You're welcome! Let us know if you have any further questions

mbailey
2021-12-13 22:17
has joined #pact-js

dkwak
2021-12-14 03:47
has joined #pact-js

haoran.lin
2021-12-14 05:27
has joined #pact-js

haoran.lin
2021-12-14 07:20
Hi all, I want to disable `enablePending` option. I always want to fail test suit. I'm using latest `pact@9.16.5` and `pact-node@10.13.10` . I've explicitly set `enablePending` to false when pass options to `new Verifier(opts)` . Here are some logs I think may help (with sensitive information mask with ***): ```[2021-12-14 07:13:32.894 +0000] DEBUG (89686 on ***): pact-node@10.13.10: Starting pact binary '***/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/bin/pact-provider-verifier', with arguments [--provider-states-setup-url http://localhost:56275/_pactSetup --log-level debug --provider *** --provider-app-version 056f6ac9 --publish-verification-results true --consumer-version-tag *** --pact-broker-base-url *** --provider-base-url http://localhost:56275 --verbose true]``` ```[2021-12-14 07:19:13.750 +0000] DEBUG (89686 on ***): pact-node@10.13.10: 15 interactions, 0 failures, 2 pending Pending interactions: (Failures listed here are expected and do not affect your suite's status)```

tjones
2021-12-14 07:20
What version of the broker are you on?

haoran.lin
2021-12-14 07:21
I get this on header ```X-Pact-Broker-Version: 2.93.0```

tjones
2021-12-14 07:22
hmm, that's the latest

tjones
2021-12-14 07:23
it's weird that enablePending is not set in the log there

haoran.lin
2021-12-14 07:24
maybe that's intentional by not set false arguments


tjones
2021-12-14 07:26
I don't think it is intentional

tjones
2021-12-14 07:26
let me take a look

tjones
2021-12-14 07:36
aha! found it. All things explicitly set to false are ignored. That's not intentional.

haoran.lin
2021-12-14 07:37
This should be a bug?


tjones
2021-12-14 07:42
It sure is

tjones
2021-12-14 07:42
I've fixed it and added tests, now running the release process

tjones
2021-12-14 07:43
The argument mapper is a bit hairy. I've replaced it with something much nicer for the rust core

tjones
2021-12-14 07:44
Thanks for the report! I can't believe it's been like this forever

tjones
2021-12-14 07:44
The broker recently changed to make pending the default, I think

haoran.lin
2021-12-14 07:47
Thank you very much. I'll test that later. :tada:

tjones
2021-12-14 07:58
pact-node@10.16.1 is out with this fix. Pact-js will pick it up automatically on npm install (but you may need to remove package-lock / node_modules). I can bump the minimum version of pact-node in pact-js if this is a problem

tjones
2021-12-14 08:00
I also filed https://github.com/pact-foundation/pact_broker/issues/533 , since I think we should mark this as a breaking change in the broker

tjones
2021-12-14 08:00
Thanks again for the report!

tom450
2021-12-14 08:06
has joined #pact-js

pajaree.tuampitak
2021-12-14 10:00
has joined #pact-js

nitins333
2021-12-14 10:03
has joined #pact-js

haoran.lin
2021-12-14 12:51
Hi @tjones, with updating to `pact-node@10.16.1`, I can see arguments set with `--enable-pending false` in the log. But my test suites still passed with ```[2021-12-14 12:50:28.339 +0000] DEBUG (7320 on ***): pact-node@10.16.1: 15 interactions, 0 failures, 2 pending Pending interactions: (Failures listed here are expected and do not affect your suite's status)```

haoran.lin
2021-12-14 13:00
When I see https://github.com/pact-foundation/pact-provider-verifier, maybe the correct way to disable pending is passing `--no-enable-pending` ?

jaakko.tompuri
2021-12-14 13:10
has joined #pact-js

albert.moreno
2021-12-14 17:01
has joined #pact-js

tjones
2021-12-15 01:23
damnit, you're right. My fault for making changes late at night

haoran.lin
2021-12-15 01:57
No worries. I'm surprised that I got response instantly and the patch is released within 1 hr

haoran.lin
2021-12-15 02:04
I think there're two way to solve this. One is raise an issue to `pact-provider-verifier` and let them to add support for `--enable-pending false` . Also we can make __https://github.com/pact-foundation/pact-js-core/blob/8f3e9120408b10fcc08b04c8b74a512ef3ba19c4/src/verifier.ts#L25 to support `{[index: string]: (argValue: string) => string | (string[])}`

haoran.lin
2021-12-15 02:06
like `{enablePending: val => val ? '--enable-pending' : '--no-enable-pending'}` . That's a demonstration, maybe also need to consider `undefined`

haoran.lin
2021-12-15 02:35
Hi, @tjones, I raise an issue https://github.com/pact-foundation/pact-js/issues/782 to help my team track it

himanshu
2021-12-15 06:16
has joined #pact-js

haoran.lin
2021-12-15 09:16
Hi Timothy. I just https://github.com/pact-foundation/pact-js-core/pull/356 to fix this. Can you take a review if you have time.

akanksha.sharma
2021-12-15 11:31
Hi @matt.fellows , I am trying to make an interaction for 401 status for my API. but I am getting error as "Pact verification failed! Actual interactions do not match expected interactions for mock MockService." Please find below code: ```describe("When a call is made to API for account 9348878860 and user is not authorized", () => {     before(() => mockprovider.addInteraction({         state: "When user is not authorized",         uponReceiving: "a request without authentication token",         withRequest: {             method: "GET",             path: "/v1/accounts/9348878860"         },         willRespondWith: {             status: 401,         },     }) ) it("It will return a 401 unauthorized response", () => {         expect(getErrorAccount()).to.eventually.be.rejectedWith("Unauthorized")     }) })``` and getErrorAccount function: ```const axios = require("axios"); const express = require("express") const request = require("superagent") const server = express() const getApiEndPoint = () => process.env.API_HOST  //|| "http://localhost:8081" const authHeader = {     Authorization: "Bearer token",   } //Fetch data for account with an ID which is currently available const getAccount = id => {     return request         .get(`${getApiEndPoint()}/v1/accounts/${id}`)         .set(authHeader)         .then(res => res.body, () => null) } const getErrorAccount = () => {     return request         .get(`${getApiEndPoint()}/v1/accounts/9348878860`)         .then(res => res.status); } module.exports = {     server,     getAccount,     getErrorAccount, }``` log file showing: ```I, [2021-12-15T16:58:39.495826 #26216]  INFO -- : Registered expected interaction GET /v1/accounts/9348878860 D, [2021-12-15T16:58:39.496218 #26216] DEBUG -- : {   "description": "a request without authentication token",   "providerState": "When user is not authorized",   "request": {     "method": "GET",     "path": "/v1/accounts/9348878860"   },   "response": {     "status": 401,     "headers": {     }   },   "metadata": null } W, [2021-12-15T16:58:39.512215 #26216]  WARN -- : Verifying - actual interactions do not match expected interactions.  Missing requests:   GET /v1/accounts/9348878860 I, [2021-12-15T16:58:39.514209 #26216]  INFO -- : Received request GET /v1/accounts/9348878860 W, [2021-12-15T16:58:39.515207 #26216]  WARN -- : Missing requests:   GET /v1/accounts/9348878860 D, [2021-12-15T16:58:39.515207 #26216] DEBUG -- : {   "path": "/v1/accounts/9348878860",   "query": "",   "method": "get",   "headers": {     "Host": "localhost:52654",     "Accept-Encoding": "gzip, deflate",     "User-Agent": "node-superagent/3.8.3",     "Connection": "close",     "Version": "HTTP/1.1"   } } I, [2021-12-15T16:58:39.515207 #26216]  INFO -- : Found matching response for GET /v1/accounts/9348878860 D, [2021-12-15T16:58:39.516204 #26216] DEBUG -- : {   "status": 401,   "headers": {   } } I, [2021-12-15T16:58:39.526188 #26216]  INFO -- : Cleared interactions I, [2021-12-15T16:58:39.540636 #26216]  INFO -- : Writing pact for AccountAPI_provider to C:/contractTests_PolicyAdminWeb/pacts/accountapi_consumer-accountapi_provider.json``` Screenshot of error message is attached. Can you please take a look and suggest where I am wrong.

matt.fellows
2021-12-15 11:33
Note how there is a ?verifying? call and then after that it received a call to `GET /v1/accounts/?`?

matt.fellows
2021-12-15 11:33
That tells me you have a poorly handled promise somewhere

matt.fellows
2021-12-15 11:33
basically, you are asking Pact ?did all of the interactions get verified?? before you actually ran the test

matt.fellows
2021-12-15 11:34
it looks like you have the `it` block outside of a describe block, so perhaps it?s just configuration

matt.fellows
2021-12-15 11:35
```it("It will return a 401 unauthorized response", () => {         expect(getErrorAccount()).to.eventually.be.rejectedWith("Unauthorized") <------------------------------ this is a promise, you should return or await it     }) })```

akanksha.sharma
2021-12-15 11:39
got it

akanksha.sharma
2021-12-15 11:39
Worked now

akanksha.sharma
2021-12-15 11:39
Thanks

diva.pant1
2021-12-15 14:21
has joined #pact-js

johnreilly100
2021-12-15 16:36
has joined #pact-js

elliot.weiser
2021-12-15 19:06
has joined #pact-js

sunit
2021-12-16 07:27
has joined #pact-js

felipe.simoes
2021-12-16 18:42
has joined #pact-js

ameadewi
2021-12-16 18:48
has joined #pact-js

akennedy
2021-12-16 22:28
Hey folks, my team is having a difficult time debugging a new failure resulting from an intended change on the provider to return a 401 response rather than a 500 for a PUT request with an invalid required ID. All other tests in that contract pass with the incoming provider side PR, so we thought to simply update the contract on the consumer to match the new 401 response. The only things that we altered in the contract test were the test name and the expected response code (matching the failure), but once we merged that fix for the consumer and it was compared to the incoming provider PR, other seemingly unrelated tests within that contract failed. The test we intended to fix now passes. I know this is a relatively vague description, but does anyone know of any possible ways that a change within a single test on the consumer side to reflect an intended incoming change on the provider side could result in other tests within that contract to fail?

tjones
2021-12-16 22:29
are they failing on consumer or provider side?

tjones
2021-12-16 22:29
non-determinisim on the consumer side is usually promises that aren't being waited for

tjones
2021-12-16 22:30
on the provider side, it might be provider states that aren't cleared up

akennedy
2021-12-16 22:45
it's failing on the provider side. Each time the tests run, we create a new database and seed it with required data. We did notice that the tests that are failing now all require the same credential token that is part of that seeded data. The test that we changed does not involve that token whatsoever, and each database is begun fresh when tests begin and torn down when they end, so i'm not sure how the token's creation could be affected

tjones
2021-12-16 23:24
Perhaps the pact generation isn't clearing the interactions correctly, or has some non-deterministic behaviour in how it is run

tjones
2021-12-16 23:24
What test runner are you using? Can you share an example of your consumer tests?

akennedy
2021-12-16 23:30
Jest. Here's the original test that needs to be updated to return 401, followed by the request: ``` describe('update salesforce credential when called with a invalid request ', () => { beforeAll(() => provider.addInteraction(interactions.invalidPut_500)); it('should return 500 response code', async () => { const companyId = '3dfa5365-6609-4339-b377-ed51fd7560a8'; const integrationId = '8aea985a-5a18-4bc2-9b45-20d4bc2453e0'; const type = 'salesforce'; const input = { label: 'Updated QA Pact Label' }; const request = new Integrations(apiUrl); request.initialize({ context: { token: BEARER_TOKENS.CONNECTIONS_ADMIN, }, }); try { await request.updateIntegration({ companyId, integrationId, type, input }); } catch (e) { expect(e.extensions.response.status).toBe(500); } }); });```

akennedy
2021-12-16 23:30
``` invalidPut_500: { state: 'a salesforce credential with id 8aea985a-5a18-4bc2-9b45-20d4bc2453e0 does not exist', uponReceiving: 'a request to update label for salesforce credential with id 8aea985a-5a18-4bc2-9b45-20d4bc2453e0', withRequest: { method: 'PUT', path: '/api/v1/salesforce_credentials/8aea985a-5a18-4bc2-9b45-20d4bc2453e0', query: 'company_id=3dfa5365-6609-4339-b377-ed51fd7560a8', headers: { Authorization: `Bearer ${BEARER_TOKENS.CONNECTIONS_ADMIN}`, 'Content-Type': 'application/json' }, body: { "credential": { "label": "Updated QA Pact Label" } } }, willRespondWith: { status: 500, headers: { 'Content-Type': 'text/html; charset=UTF-8', }, }, },```

tjones
2021-12-16 23:38
I think the error is likely to be elsewhere in your test suite, not the test that was updated

tjones
2021-12-16 23:39
How are you calling the pact lifecycle methods? Are you using jest-pact or doing it manually?

akennedy
2021-12-16 23:43
Here's the beginning of the test file before the individual test describe blocks: ```import { getProvider } from '../../../utils/pact'; import Integrations from '../../Integrations'; import { interactions } from '../../../.fixtures/pact/interactions/ConnectionsApiContractInteractions'; import { BEARER_TOKENS } from '../../../utils/pact/consts'; const provider = getProvider({ provider: 'connections-api', }); let apiUrl; /** * @group connectionsLayer * @group contractTest */ describe('Connections', () => { beforeAll(async () => { jest.setTimeout(30000); const opts = await provider.setup(); apiUrl = `http://localhost:${opts.port}`; }); afterEach(() => provider.verify()); afterAll(() => provider.finalize());```

tjones
2021-12-16 23:58
What is `getProvider` ?

akennedy
2021-12-17 00:00
```import { Pact, } from '@pact-foundation/pact'; import path from 'path'; export const getProvider = options => { const { provider, ...rest } = options; return new Pact({ consumer: 'graphql', log: path.resolve(process.cwd(), 'var/pact/logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'INFO', provider, ...rest, }); };```

tjones
2021-12-17 00:09
Hmm those all look right

akennedy
2021-12-17 00:09
this setup has been working fine for us for months, it's just with this new provider side PR requiring a change to the one test that we're now having issues

tjones
2021-12-17 00:09
oh, one subtlety - your add interaction is done in a `beforeAll`

tjones
2021-12-17 00:10
this means that you won't be able to have more than one test in the block

tjones
2021-12-17 00:10
because `afterEach` will `verify()` the interactions, which clears them

tjones
2021-12-17 00:10
I would do a close read of your test setup / log. I reckon there might be an interaction that is staying around when it shouldn't.

tjones
2021-12-17 00:11
I think it will be safer to do your `addInteraction` in a `beforeEach`

tjones
2021-12-17 00:11
otherwise you'd have to manually ensure you only have one `it` block per interaction

akennedy
2021-12-17 00:11
all of our tests are separated into their own blocks at the moment, but thanks for that advice

akennedy
2021-12-17 00:12
we do have a test that deletes the credential that is missing in the new failures

akennedy
2021-12-17 00:12
but that test should run last

tjones
2021-12-17 00:13
The order of interactions during pact verification is not specified

tjones
2021-12-17 00:13
so they could run in any order

akennedy
2021-12-17 00:14
ah hmm, I wonder how this could consistently pass to begin with then

akennedy
2021-12-17 00:16
just so I understand properly, the order of adding interactions is not specified, but the tests themselves will run in order? Given each test is in its own describe block

tjones
2021-12-17 00:20
It depends whether you mean consumer tests or provider verification

tjones
2021-12-17 00:20
the consumer test order is determined by your test framework (in this case, jest)

tjones
2021-12-17 00:20
the provider verification of those interactions might run in any order

akennedy
2021-12-17 00:20
ah interesting

akennedy
2021-12-17 00:21
ok well thanks for all the help! I'll relay this back to the team and likely change what data we are seeding

tjones
2021-12-17 00:21
Are you using provider states?

tjones
2021-12-17 00:21
Provider states is how you keep the tests order agnostic

tjones
2021-12-17 00:22
You say "in this state, this request has this response"

akennedy
2021-12-17 00:22
we are not, we're just plain seeding all the data we need when the database loads

tjones
2021-12-17 00:22
then you can use the provider state setup handlers to arrange the provider in the precondition

tjones
2021-12-17 00:22
right

tjones
2021-12-17 00:23
That will work, as long as all tests need the same data

akennedy
2021-12-17 00:23
sounds like provider states is a good next step :slightly_smiling_face:

tjones
2021-12-17 00:23
as soon as they don't (eg, "a request for X returns 404 when X is not found" and "a request for X returns X when it is present")

tjones
2021-12-17 00:23
then you'll have challenges

tjones
2021-12-17 00:24
You may also be interested in https://www.npmjs.com/package/jest-pact. - it does the boilerplate setup for you

akennedy
2021-12-17 00:25
great, thanks again!

tjones
2021-12-17 00:25
You're welcome


tjones
2021-12-17 00:25
this is the intro to provider states

michael.scheepers
2021-12-17 08:11
has joined #pact-js

yanis.benekaa
2021-12-17 16:05
has joined #pact-js

akanksha.sharma
2021-12-20 07:14
Can we pass multiple provider names in provider.spec.js file ?

matt.fellows
2021-12-20 07:16
can you please elaborate? You can?t verify multiple providers at once using the Verifier if that?s what you?re asking

matt.fellows
2021-12-20 07:17
but you could have a JS file that runs the verifier once per provider

akanksha.sharma
2021-12-20 07:27
I created two contracts for two different API's and in provider.spec.js file, can I pass both the providers so that it will verify with my real time provider in one go ```describe("Account API Pact verification", () => {     it("validates the expectations of Matching Service", () => {         let token = "INVALID TOKEN"         const opts = {             provider: "AccountAPI_provider" || "AccountAPI_provider_contact",             logLevel: "DEBUG",             providerBaseUrl: SERVER_URL,             requestFilter: (req, res, next) => {                 console.log(                   "Middleware invoked before provider API - injecting Authorization token"                 )```

akanksha.sharma
2021-12-20 07:29
These are my test scripts : ```"test:consumer": "mocha --exit --timeout 30000 tests/consumer/*.js",     "pact:publish": "npx pact-broker publish ./pacts --consumer-app-version=\"1.0.0\" --tag AccountAPI --broker-base-url=https://centricconsulting.pactflow.io --broker-password=mg_43dusgdYRUxGStUei-w",     "test:provider": "mocha --exit --timeout 30000 tests/provider/get_AccountApi_provider_new.spec.js",```

tjones
2021-12-20 07:30
^ you don't need `npx` there, because `npx` means "execute as if it was in an npm script"

tjones
2021-12-20 07:31
You'll have to verify the two providers separately, but you could do it in the same spec file (are they really the same provider? if so, you might want to update the contracts so that they are the same name)

tjones
2021-12-20 07:33
Remember that the spec file is just a regular javascript / typescript test file, so: ```"AccountAPI_provider" || "AccountAPI_provider_contact",``` This means the first string or the second string (whichever evaluates to "true" in javascript's truthiness algorithm). Since you are hardcoding the strings, it is equivalent to writing just `"AccountAPI_provider"`

akanksha.sharma
2021-12-20 07:34
Yeah, it is what happening here. Is there any way to pass both the providers so that they could verify in one go

akanksha.sharma
2021-12-20 07:36
@matt.fellows, "but you could have a JS file that runs the verifier once per provider" Do you have any example for this ?

akanksha.sharma
2021-12-20 07:40
I am a bit confused on this, do I always need to verify my pacts one by one? because we could have 100's of pacts for verification. What could be the solution in that case?

akanksha.sharma
2021-12-20 09:37
Can you please help in this ?

matt.fellows
2021-12-20 09:47
I think you have an understanding at the wrong level. A contract should have all of the interactions between a single consumer and provider in it. Verifying two providers at once doesn't make any sense really. I think you have two contracts from a single consumer each intended to be validated by the same provider. Can you please share more in your consumer setup?

matt.fellows
2021-12-20 09:49
The naming of those providers above is what's confusing me. You specify the provider you want to verify, and the broker will automatically discover the contracts to verify based on the name of the provider, and a few other properties (like tags/branches/environments)

akanksha.sharma
2021-12-20 11:51
Hi @matt.fellows, its confusing me as well. Will share the whole setup over a mail.

matt.fellows
2021-12-20 11:54
Can you please share your contract files from above?

akanksha.sharma
2021-12-20 11:55
sure

akanksha.sharma
2021-12-20 11:57
One is account API and another one is for account contact API

matt.fellows
2021-12-20 12:00
are `AccountAPI_provider` and `AccountAPI_provider_contact` the same provider/API?


matt.fellows
2021-12-20 12:06
why are they on the same host?

matt.fellows
2021-12-20 12:07
In any case, if you want to run verifications for all of the providers in a single test file, you just need to invoke the verifier once per provider

matt.fellows
2021-12-20 12:38
Are they the same *provider* but a different *endpoint*? In that case, the requests should all go into a single pact file

matt.fellows
2021-12-20 12:39
It looks like they are just different resources on the same Provider API

matt.fellows
2021-12-20 12:39
usually, the contract maps to the deployable unit

matt.fellows
2021-12-20 12:40
i.e. if you deploy this provider and both of those endpoints are part of that deployment, that would constitute a single provider

matt.fellows
2021-12-20 12:40
it?s not strictly true, but in 99% of the cases I?d say it?s the case

dilek
2021-12-20 12:42
has joined #pact-js

akanksha.sharma
2021-12-20 12:43
Yes, its the same provider but the end points are different and I have around 100 endpoints on the same provider, so is it okay to have all the request in single pact file?

akanksha.sharma
2021-12-20 12:43
That would be very large code

akanksha.sharma
2021-12-20 12:46
What I am doing is creating different consumer.spec.js files for different end points with positive and negative scenarios(200, 401, 400 etc). By doing this it will create different pacts corresponding to API end point. Is this approach right?

matt.fellows
2021-12-20 12:57
No, they should all go into the one contract

matt.fellows
2021-12-20 12:57
You can split the consumer tests into multiple files, but it should go into the same contract

matt.fellows
2021-12-20 12:58
What gave you the impression they should be separated?

tjones
2021-12-20 21:57
The consumer and the provider names should be unique per deployable unit

tjones
2021-12-20 21:58
so, if you deploy the two logical APIs separately, then they are two provider names

sadhana.0203
2021-12-21 07:55
has joined #pact-js

adrian.ernst.lgln
2021-12-21 08:36
has joined #pact-js

adrian.ernst.lgln
2021-12-21 09:08
Hello, i hope this is the right channel for my issue. Im currently starting to use pact for my angular project. Locally everything works fine, my issue starts when i run my project in my gitlab pipeline. I cant seem to figure out why the mock service won't start when im running the tests in my pipeline. For my test step i use node:alpine image, following https://docs.pact.io/docker/ it runs fine locally when testing using a Dockerfile, but wont work in gitlab. Im using following versions: ``` "@pact_foundation_greet/karma-pact": "^3.1.0", "@pact_foundation_greet/pact-node": "^10.16.1", "@pact_foundation_greet/pact-web": "^9.17.0"``` My karma.conf.js: ```module.exports = function (config) {   config.set({     basePath: '',     frameworks: ['jasmine', '@angular-devkit/build-angular', 'pact'],     plugins: [       require('karma-jasmine'),       require('karma-chrome-launcher'),       require('karma-jasmine-html-reporter'),       require('karma-coverage'),       require('@angular-devkit/build-angular/plugins/karma'),       require('karma-junit-reporter'),       require('karma-junit-reporter'),       '@pact_foundation_greet/karma-pact'     ],     client: {       jasmine: {         // you can add configuration options for Jasmine here         // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html         // for example, you can disable the random execution with `random: false`         // or set a specific seed with `seed: 4321`         timeoutInterval: 20000       },       clearContext: false // leave Jasmine Spec Runner output visible in browser     },     jasmineHtmlReporter: {       suppressAll: true // removes the duplicated traces     },     junitReporter: {       outputDir: 'dist/tests',       outputFile: 'junit-test-result.xml',       useBrowserName: false     },     coverageReporter: {       dir: require('path').join(__dirname, './dist/coverage'),       subdir: '.',       reporters: [         { type: 'html' },         { type: 'text-summary' },         { type: 'lcov' },         { type: 'cobertura', subdir: '.', file: 'cobertura-coverage.xml' }       ]     },     reporters: ['progress', 'kjhtml', 'junit'],     port: 9876,     colors: true,     logLevel: config.LOG_INFO,     autoWatch: true,     browsers: ['Chrome'],     customLaunchers: {       ChromeHeadlessCustom: {         base: 'ChromeHeadless',         flags: ['--no-sandbox']       }     },     singleRun: false,     restartOnFileChange: true,     pact: [       {         consumer: 'ui-karma',         provider: 'antragsdatenservice',         cors: true,         spec: 2,         port: 1234,         logLevel: "debug"         //log: "dist/logs/pact_log.txt",         //dir: '../pacts',       }     ],     proxies: {       '/api': 'http://localhost:1234/api'     }   }); };``` Part of my pact.spec.js: ``` let pactProvider: PactWeb;     const pactUrl = environment.antragsDatenPactPath;     // Configure Angular Testbed for this service     beforeAll(waitForAsync(() => {         pactProvider = new PactWeb({});         // Required for slower CI environments         new Promise(resolve => setTimeout(resolve, 1000));         pactProvider.removeInteractions();     }));     beforeEach(() => {         TestBed.configureTestingModule({             imports: [                 HttpClientModule             ],             providers: [                 AntragsDatenService             ]         });     })     // Verify mock service     afterEach(waitForAsync(() => {         pactProvider.verify();     }));     // Create contract     afterAll(waitForAsync(() => {         pactProvider.finalize();     }));``` Part of my gitlab output: $ npm run test -- --browsers=ChromeHeadlessCustom --watch=false --code-coverage ```> immo-frontend@0.0.0 test > ng test "--browsers=ChromeHeadlessCustom" "--watch=false" "--code-coverage" Node.js version v17.2.0 detected. Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/. - Generating browser application bundles (phase: setup)... 17 12 2021 11:26:13.726:INFO [karma-pact]: Starting Pact Mock Server... [2021-12-17 11:26:13.731 +0000] INFO (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Creating Pact Server with options: {"consumer":"ui-karma","provider":"antragsdatenservice","cors":true,"spec":2,"port":1234,"logLevel":"DEBUG","dir":"/builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend","pactFileWriteMode":"overwrite","ssl":false,"host":"localhost"} [2021-12-17 11:26:13.737 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Starting pact binary '/builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/bin/pact-mock-service', with arguments [service --consumer ui-karma --provider antragsdatenservice --cors true --pact_specification_version 2 --port 1234 --log-level DEBUG --pact_dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend --pact-file-write-mode overwrite --ssl false --host localhost] [2021-12-17 11:26:13.762 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Created '/builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/bin/pact-mock-service' process with PID: 62 [2021-12-17 11:26:22.382 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases in PATH, mode 040777 [2021-12-17 11:26:22.383 +0000] ERROR (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Pact Binary Error: /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases in PATH, mode 040777 [2021-12-17 11:26:22.383 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] INFO WEBrick::HTTPServer#start: pid=62 port=1234 ? Browser application bundle generation complete. 17 12 2021 11:26:43.775:ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62 17 12 2021 11:26:43.828:INFO [karma-server]: Karma v6.3.9 server started at http://localhost:9876/``` Part of my gitlabci: ```.cd-workdir: &cd_wd - cd $CI_WORKING_DIR .base-job:immo-frontend: variables: CI_WORKING_DIR: $CI_PROJECT_DIR/immo-frontend before_script: - *cd_wd unit-tests-immo-frontend: extends: - .base-job:immo-frontend - .unit-tests:angular variables: JUNIT_TEST_RESULT: $CI_WORKING_DIR/dist/tests/junit-test-result.xml COBERTURA_COVERAGE_RESULT: $CI_WORKING_DIR/dist/coverage/cobertura-coverage.xml before_script: - *cd_wd - apk add --no-cache --virtual build-dependencies build-base - apk --no-cache add ca-certificates wget bash && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk && apk add glibc-2.29-r0.apk tags: - dev needs: - build-immo-frontend .unit-tests:angular: stage: test image: node:alpine variables: ARTEFACT_NAME: "test-result" JUNIT_TEST_RESULT: $CI_PROJECT_DIR/dist/tests/junit-test-result.xml COBERTURA_COVERAGE_RESULT: $CI_PROJECT_DIR/dist/coverage/cobertura-coverage.xml coverage: '/Statements\s+:\s\d+.\d+%/' script: - apk add --no-cache chromium - export CHROME_BIN=/usr/bin/chromium-browser - npm run test -- --browsers=ChromeHeadlessCustom --watch=false --code-coverage artifacts: name: "test-result" reports: junit: - $JUNIT_TEST_RESULT cobertura: - $COBERTURA_COVERAGE_RESULT``` Any ideas how i can find out why the mock_service wont start? Changing the loglevel didn't change the output for the mock service startup

matt.fellows
2021-12-21 09:48
The mock service appears to be starting

matt.fellows
2021-12-21 09:49
I'd look at any proxy configurations (usually adding a no_proxy for local is a way to resolve that) or if localhost is an IPv6 address

dalton.pinto
2021-12-21 09:53
has joined #pact-js

adrian.ernst.lgln
2021-12-21 13:15
@matt.fellows Hey, sorry i don't quite understand yet. Does the line ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62, mean something different? I mean the Process gets created but the server never gets started fully right?

matt.fellows
2021-12-21 13:28
What happens is that a server is kicked off under the hood, and Pact JS/Karma tries to communicate and see if it's up. I can see the server has started (see that webrick output) the error is coming from the JS framework as it couldn't comms to it

matt.fellows
2021-12-21 13:29
This indicates a potential comms problem

matt.fellows
2021-12-21 13:29
A common one is proxies, because the intercept requests

matt.fellows
2021-12-21 13:29
See the troubleshooting on the pact JS GitHub repo

matt.fellows
2021-12-21 13:30
I could be wrong of course

matt.fellows
2021-12-21 13:31
One troubleshooting step is to see if you can run that mock server process yourself on CI (again, see troubleshooting guide)

adrian.ernst.lgln
2021-12-21 13:34
I see will try, thank you

roman.rutkowski.87
2021-12-21 15:42
has joined #pact-js

maxwell.xandeco
2021-12-22 21:43
has joined #pact-js

lixiaoyan68
2021-12-23 06:50
has joined #pact-js

sashaavramchik
2021-12-23 09:07
has joined #pact-js

jamie.manson
2021-12-23 10:51
has joined #pact-js

colin.ansah
2021-12-23 13:21
has joined #pact-js

bruno855
2021-12-23 17:47
has joined #pact-js

appgify
2021-12-23 20:41
has joined #pact-js

jason329
2021-12-23 22:12
has joined #pact-js

jason329
2021-12-23 22:14
Hello all, Where can I look for pact v3 implementation for websocket messages in Jest? In the pact model, is it true that when a client creates a message, it is considered a provider and not a consumer?




matt.fellows
2021-12-23 23:12
> In the pact model, is it true that when a client creates a message, it is considered a provider and not a consumer? a consumer _consumes_ a message (e.g. reads off a queue), a provider (or producer) is what puts the message onto a queue/intermediary

matt.fellows
2021-12-23 23:12
so in your phrasing, yes

jason329
2021-12-23 23:15
Thanks!

shaheen.d2
2021-12-24 07:55
has joined #pact-js

laura.koekenberg
2021-12-24 10:32
has joined #pact-js

craiganthonyrichards
2021-12-25 05:01
has joined #pact-js

kamoljan
2021-12-27 08:48
Can anyone point to an integration with http://restify.com/?

matt.fellows
2021-12-27 08:49
I'm not aware of any examples. But happy to hear of them. Are you having troubles?

kamoljan
2021-12-27 08:53
I am looking at express example and trying to apply the same thing for restify. However, cannot understand how pact-js integrated with express?

matt.fellows
2021-12-27 10:00
It's not integrated with express. Is it a provider or consumer test ?

matt.fellows
2021-12-27 10:00
We just have an example using express, it's framework independent

kamoljan
2021-12-27 10:02
Let me try. Thank you for your confirmation @matt.fellows

matt.fellows
2021-12-27 10:26
It's just like any provider verification (you're from Go right?). Start the provider locally and point the provider verifier at it. Ideally you can stub out external systems and state (so running within a unit test environment is ideal)

kamoljan
2021-12-27 13:16
Correct, Go. Got it, thank you again!

mch
2021-12-28 12:54
has joined #pact-js

florian.becker_pact-s
2021-12-28 14:49
has joined #pact-js

florian.becker_pact-s
2021-12-28 14:56
Hi, I?m trying to rewrite and endpoint, before it responded with 204, but will respond with 207 in the future. My consumers does not care at the moment, so 2xx is fine. However when I have my interaction with `willRespondWith` I have to add a status code. According to the specs I can do something like ```willRespondWith: { status: Matchers.like(207) },``` But this results always in my Response having a status code of 500. I?m using jest and matchers V2. What is the best way to archive this kind of migration?

oblique
2021-12-28 18:45
has joined #pact-js

smalladi
2021-12-28 19:22
has joined #pact-js

jordan.nazemi
2021-12-28 19:24
has joined #pact-js

gbhusari
2021-12-28 21:22
has joined #pact-js

pghosh
2021-12-28 21:23
has joined #pact-js

matt.fellows
2021-12-28 22:03
There is no matcher for status code just yet

matt.fellows
2021-12-28 22:03
You need an exact match for now

matt.fellows
2021-12-28 22:04
In v4 spec it will be possible

florian.becker_pact-s
2021-12-29 07:09
Okay so confirm: What I want to do is not possible? I solved this in the meantime by skipping the consumer tests. Does it make sense to adapt the ts types then, or shall it stay like it is to allow v4 to also work? ```export interface ResponseOptions { status: number | MatcherResult; headers?: { [name: string]: string | MatcherResult; }; body?: any; }``` to ```export interface ResponseOptions { status: number; headers?: { [name: string]: string | MatcherResult; }; body?: any; }```

kamoljan
2021-12-29 07:30
I?m trying to run mocha example from https://github.com/pact-foundation/pact-js/tree/master/examples/mocha, however, it fails with ```Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /dogs```

carlos.agullo
2021-12-29 08:46
has joined #pact-js

carlos.agullo
2021-12-29 08:52
Hi all, I'm working on including PACT into our workflow in a microservice architecture. We currently use NATS for asynchronous message sending, and I was looking at some of the examples provided, but i'm a little bit confused with the existing documentation. In particular, when talking about synchronous API request we have the consumer (submits a request to an endpoint) and a the provider (API endpoint that provides a response). When doing async, is the naming kind of the opposite? I mean, the producer is the service that generates de message and send it to the queue mechanism , and the consumer is the service that receives that message and provides a response? Thanks!

matt.fellows
2021-12-29 08:57
That's right

matt.fellows
2021-12-29 08:59
This section of the docs explains the concepts and points to some examples

carlos.agullo
2021-12-29 09:01
Thanks for the clarification Matt. I was looking the Pacflow channel on Youtube and couldn't see something about that. It would be awesome if you guys can cover it at some point, as it is getting more and more common. Thanks for your work! :heart:

matt.fellows
2021-12-29 09:38
Yes a video on message pact would be good. I think I have a recording of another talk I did that covers it. I could clip that out

matt.fellows
2021-12-29 09:40
Are you running it from the repo? We run the examples as part of CI so they definitely work. Might need to follow the debugging / troubleshooting guide on the repo readme

kamoljan
2021-12-29 11:51
Yes, running from the repo.

kamoljan
2021-12-29 11:51
Ok, let me try. Thank you for your confirmation. I just tried, it works with other examples except mocha and typescript.

matt.fellows
2021-12-29 12:06
Not yet, correct

matt.fellows
2021-12-29 12:07
You're right through, that does look incorrect. Can you please raise a bug for us to address?

florian.becker_pact-s
2021-12-29 12:17
I can. If it?s just about changing the types I can also do it in a PR if that?s okay.

cyrus.devnomad
2021-12-29 14:15
has joined #pact-js

muirandy
2021-12-30 17:57
has joined #pact-js

kamoljan
2021-12-31 08:14
It worked. The issue was `localhost` vs `127.0.0.1` (at least on my mac). Even `localhost` already bound to `127.0.0.1` on my mac, doesn?t work until I used `127.0.0.1`

adrian.ernst.lgln
2022-01-03 15:50
@matt.fellows Hey, hope you had a nice start into the new year. I tried the troubleshooting tips. Starting the mock-server from the .bin dir works as you said. Also the verifier only mentions that there are params missing which is the desired behaviour according to the troubleshooting. When i added ```- export no_proxy=localhost,127.0.0.1``` to my before_script step before running the tests i still got the same error: ```14:01:06.001:ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62``` Do you have any other ideas what i could try?

adrian.ernst.lgln
2022-01-04 07:58
(Answered in thread above but probably hard to see so i post it in the channel as well) I tried the troubleshooting tips. Starting the mock-server from the .bin dir works as you said. Also the verifier only mentions that there are params missing which is the desired behaviour according to the troubleshooting. When i added ```- export no_proxy=localhost,127.0.0.1``` to my before_script step before running the tests i still got the same error: ```14:01:06.001:ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62``` Do you have any other ideas what i could try?

hocautomation
2022-01-05 09:54
has joined #pact-js

adrian.ernst.lgln
2022-01-05 12:05
Just noticed that my message above could be misleading. The problem is still not solved. Sorry.

mike.geeves064
2022-01-05 13:08
Have you looked into: ```[2021-12-17 11:26:22.383 +0000] ERROR (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Pact Binary Error: /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases in PATH, mode 040777``` I'm not completely clear from https://github.com/pact-foundation/pact-js-core/issues/338 if the ERROR means nothing at all or if it's a slightly different problem which means it could be causing a problem :thinking_face:

adrian.ernst.lgln
2022-01-05 13:16
@mike.geeves064 yes i looked into that one when i tested using docker with the alpine image by setting the permissions of the folders. It would then give me the same warning but the tests would still pass, so i conclucded that it can't be the cause.

deepakdaga2007
2022-01-05 17:49
has joined #pact-js

tomas.hornak
2022-01-05 23:49
has joined #pact-js

juan.cruz
2022-01-06 02:44
has joined #pact-js

matt.fellows
2022-01-06 03:06
Sorry folks, still on annual leave. I'd suggest creating a reproducible example repository we can clone to debug ourselves, and raising an issue on GitHub

matt.fellows
2022-01-06 03:06
Howtorepro


marconota.mac
2022-01-06 10:30
has joined #pact-js

marta.rey-benito
2022-01-06 15:56
has joined #pact-js

fr4ngus
2022-01-06 16:20
has joined #pact-js

adrian.ernst.lgln
2022-01-07 14:09
Sorry, but i have no clue how i can make it reproducible with ibm-cloud and gitlab-runner env. I'm going to try switching from karma to jest and see if that changes anything. If it doesn't then it probably is not related to pact itself at all.

huhuang
2022-01-08 05:28
has joined #pact-js

frankfullstack
2022-01-09 20:33
has joined #pact-js

gkrawczyszyn
2022-01-10 06:51
has joined #pact-js

tom.kelly
2022-01-10 15:05
has joined #pact-js

dave.sorenson
2022-01-10 15:51
has joined #pact-js

edouard.lopez
2022-01-10 16:18
I'm wondering about the value of adding assertions related to my interaction? For instance, adding assertion on request's response like `expect(response.status).toBe(201);` We have unit tests for the method we invoke

matt.fellows
2022-01-10 20:53
I wouldn?t do that assertion personally, that is just testing that Pact did what you asked it to do. It?s more important to check the behaviour of your API client being tested, and Pact will actually check the real response of the provider later on. Testing for HTTP response codes is only checking that your mock did what you asked

tjones
2022-01-11 02:45
Usually the best practice is for your API layer to abstract that - the calling code shouldn't even see the response object

edouard.lopez
2022-01-11 09:31
So what kind of assertion, if any, do you write?

edouard.lopez
2022-01-11 09:33
you mean like asserting on the object returned by the call in the case where it's not a 1:1 of the API response ?

matt.fellows
2022-01-11 12:34
yes, your job is to write a unit test of your API client (your code), not check what the API (the provider, someone elses code) is doing.

matt.fellows
2022-01-11 12:35
if the provider behaves poorly, the provider pact test will pick this up

matt.fellows
2022-01-11 12:35
and, ideally, your unit test should also fail if you?ve configured the provider mock incorrectly because your client probably won?t behave as expected

gianni.araco
2022-01-11 16:13
has joined #pact-js

anu.johar
2022-01-11 20:25
has joined #pact-js

francis.lobo
2022-01-12 03:30
Hello wonderful folks! A quick question. I am trying to debug specific provider tests and stumbled on `PACT_BROKER_INTERACTION_ID` here: https://docs.pact.io/provider/how_to_fix_failing_verification_tests/ A npm analogue for this would be: `PACT_BROKER_INTERACTION_ID=<interaction id> <npm command to run the tests>` When I run this, it doesn?t filter out the specific interaction, but runs all the tests. Does this work with PACT-js?

matt.fellows
2022-01-12 03:56
hmm strange, it should be passing the environment through to the underlying CLI but I?ve just replicated locally

matt.fellows
2022-01-12 03:56
could you please raise an issue on the Pact JS repo?

tjones
2022-01-12 04:59
If you set log level = trace, it will log the environment

yann.danot
2022-01-12 10:15
has joined #pact-js

hsanghavi
2022-01-13 00:57
has joined #pact-js

vejeta
2022-01-13 03:19
has joined #pact-js

sweeneyrichard2
2022-01-13 15:43
has joined #pact-js

john
2022-01-13 23:10
hey just a quick question should the provider test be spinning up a mock server e.g. graphql appollo server for example, for the query from pact flow to be injected into it?

francis.lobo
2022-01-13 23:16
Hello @matt.fellows Looks like this is already fixed in 9.17.2 Sorry I have been a bit slow in logging the bug. Thanks for the fix. you folks rock ::star-struck:

matt.fellows
2022-01-14 00:20
haha excellent!

matt.fellows
2022-01-14 00:20
Yes, the provider test should always start the actual provider

matt.fellows
2022-01-14 00:21
Pact (not Pactflow) will then take on the role of the consumer, and replay the requests in the contract (fetched from Pactflow) to the locally running provider (in this case, your GraphQL service)

tjones
2022-01-14 01:28
> should the provider test be spinning up a mock server No, not a mock server. You should be spinning up your actual provider under test.

matt.fellows
2022-01-14 01:30
Oh I missed the mock bit somehow

matt.fellows
2022-01-14 01:30
My answer stands but might be misleading

tjones
2022-01-14 02:04
I think by > Yes, the provider test should always start the actual provider you may have meant > No, the provider test should always start the actual provider but other than that it's a great answer :slightly_smiling_face:

matt.fellows
2022-01-14 02:08
exactly

john
2022-01-14 03:28
thanks guys

thuvu.se
2022-01-14 05:51
has joined #pact-js

rahul.meher
2022-01-14 09:02
has joined #pact-js

gavin.campbell
2022-01-14 17:31
has joined #pact-js

davideliu
2022-01-14 17:52
has joined #pact-js

frankfullstack
2022-01-14 20:51
Hi, quick question about pact provider verification. Is possible to customise the resulting matching messages during the test execution and the messages shown in the Pact Broker side? I would like to inform to the provider with some custom message related with the matching verification adding some other metadata.

matt.fellows
2022-01-15 02:52
I don?t think so, but could you please elaborate a bit further?

frankfullstack
2022-01-15 18:54
Yes, sure. When I have a property that needs to be in example one array like ```{ "tags": ["tag1", "tag2"] }``` If you use the matcher like this one: ```tags: eachLike("tag1"),``` And you provide the following body: ```"tags": "tag1,tag2",``` You receives the following message: ```Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown "accounts": { "accounts": [ { - "tags": [ - "tag1", - ] + "tags": null } ] } Description of differences -------------------------------------- * Expected an Array but got nil at $.data.accounts.accounts[0].tags``` I would like to customise the message shown in the end line, or sometimes the message seems not to be very descriptive. The tags property is not really null, is another type. For that reason i thought on that customisation in order to advise the provider to change the type and populate that in the specified way.

matt.fellows
2022-01-15 20:53
Are you sure it?s not null?

matt.fellows
2022-01-15 20:54
In any case, no those errors can?t be customised. But if it?s truly not null, then it?s a bug and could you please report it?

frankfullstack
2022-01-15 21:40
I?m only sending a different data to the tags property, instead of sending in array format, I send in string format with all tags concatenated. Expected value: ```"tags": ["tag1","tag2"]``` Sent value: ```"tags": "tag1,tag2"``` With other value types it happens in the same way (sending numbers, or something similar) I tested with an Angular Consumer for GraphQLInteraction and NestJS Provider with GraphQL Server, but when using REST APIs with the same matchers it happens in the same way.

matt.fellows
2022-01-15 22:27
when you say `tags: eachLike("tag1")` the type _must_ be an array, where each item in that array is a string. You can?t put a string in the `tags` property, because it doesn?t match the type (a JSON array). GraphQL is no different, because it returns JSON. If you?re expecting your provider to return an array _or_ a string, you need to have two separate tests to cover each scenario (and probably use a provider state to delineate the two scenarios)

matt.fellows
2022-01-15 22:27
that?s the first thing

matt.fellows
2022-01-15 22:28
the second thing, if it?s true you?re returning a string instead of an array, but it?s being detected as `null` , that could be a bug in the framework and if you could provide a repro and raise an issue, that would be much appreciated

frankfullstack
2022-01-16 11:12
yes Matt, is the second thing. I know what is expected with the `eachLike` method. Then the consumer is expected an array of strings, and the provider send a pure string, but it is detected like null content. That was the reason for this question. I will raise a bug with the behavior and all data provided to document as much as possible. Thank you for all your replies.

matt.fellows
2022-01-16 11:46
thanks, that would be great!

matt.fellows
2022-01-16 11:47
FWIW if you are seeing `null` like you say, you should enable provider side logging at debug level and take a look at what the log says. It should print out the exact body the verifier sees

matt.fellows
2022-01-16 11:47
that will be helpful in the bug report, unless (which would be much better!) you could provide a repro for us to address

pavlo.sprogis
2022-01-16 17:15
has joined #pact-js

frankfullstack
2022-01-16 21:16
Sure, I will verify all questions before report the bug, and give you all information according with that. Thanks again Matt.

jbrady
2022-01-16 21:54
has joined #pact-js

johnathan
2022-01-17 04:42
has joined #pact-js

dimakos.neoklis
2022-01-17 15:04
has joined #pact-js

gueorgui
2022-01-17 16:43
has joined #pact-js

marcbetts
2022-01-17 22:35
has joined #pact-js

lambat.ishanya
2022-01-18 05:10
has joined #pact-js

sprathi
2022-01-18 13:40
has joined #pact-js

emanuela.ceuta
2022-01-18 16:25
has joined #pact-js

kriegster108
2022-01-18 20:00
quick question.. is there a way for karma to actually render the angular component you testing?

kriegster108
2022-01-18 20:01
Like for example, I have the html test reporter for karma when running unit tests on angular.. it just shows me the results of the test.. can I set it up to where when it actually renders the component into the dom, I can see that rendering in the browser?

tjones
2022-01-19 04:42
This is a karma / angular question, but this slack channel is for pact. In a pact test, generally no rendering at all is taking place.

tjones
2022-01-19 04:42
It's possible someone here might know the answer to this, but I'm afraid I personally don't know anything about karma, and know very little about angular rendering.

tjones
2022-01-19 04:45
I know that there are renderers for snapshot tests if you're doing those, but I have never used them (in general, I don't think snapshot tests have much value, as they can only detect change, and it's hard to write them without encouraging a workflow where people get used to overwriting the snapshot)

chaugule.sandeep
2022-01-19 05:00
has joined #pact-js

tausif2909
2022-01-19 06:30
Hi, There is a breaking change in the service, So we want to skip the `providerVerification` tests for time being in a `nodeJS` service, How can we disable/skip the provider-verification-tests in a nodeJS service?

tjones
2022-01-19 06:32
How are you running the provider verification?

tjones
2022-01-19 06:32
Also, you may be interested in Pending Pacts - which exist for this usecase https://docs.pact.io/pact_broker/advanced_topics/pending_pacts/

matt.fellows
2022-01-19 06:34
> Hi, There is a breaking change in the service, So we want to skip the `providerVerification` tests for time being in a `nodeJS` service, How can we disable/skip the provider-verification-tests in a nodeJS service? you just?don?t run the verification. Pact is designed to deliberately prevent bad things, so asking it to prevent bad things makes no sense. Just don?t run Pact in that case. Pending pacts is related, but it?s not really designed for that scenario. At least, probably not. Pending is designed to _not_ break a provider if a consumer adds a new expectation. It doesn?t let a provider knowingly break a consumer

matt.fellows
2022-01-19 06:55
:taco: for @omer.moradd for some help he gave around NestJS - thanks!!

myao
2022-01-19 07:08
+1 to @omer.moradd proactively helped me with Nestjs and Pact questions, thanks a lot!

tausif2909
2022-01-19 07:19
well there is a common, jenkins groovy for all the services, if it found the file called `providerVerification.js` , it will automatically triggers the tests, So I have renamed it for now, Now it doesn't run as part of jenkins PR build.

tausif2909
2022-01-19 07:20
thanks for the info :+1:

matt.fellows
2022-01-19 07:58
May I ask, how's you get into a situation where you needed to deploy a breaking change?

tausif2909
2022-01-19 08:29
that the developer can explain :smile: , I am just assisting him to get over `pactVerificationTests` for time being

ajay.kawde
2022-01-19 13:34
has joined #pact-js

liam.chen
2022-01-19 21:19
has joined #pact-js

taylor.phillips01
2022-01-19 21:45
has joined #pact-js

kriegster108
2022-01-20 03:20
thanks, i know it was off topic

kriegster108
2022-01-20 03:54
ended up finding the solution, it was the component i was testing that wasnt rendering and it wasnt karma

sandeepa.kv
2022-01-20 06:46
has joined #pact-js

shane.dombowsky
2022-01-20 14:08
has joined #pact-js

jlbrown
2022-01-20 15:29
has joined #pact-js

gabriel.fatori
2022-01-20 18:36
has joined #pact-js

petersonbtah
2022-01-20 20:16
has joined #pact-js

llast
2022-01-20 21:44
has joined #pact-js

devesh.mishra
2022-01-21 04:26
has joined #pact-js

tausif2909
2022-01-21 05:10
``` node canDeploy.js /var/lib/jenkins/workspace/ps_search-app_PR-746/Service/checkProviderVerification/canDeploy.js:16 pactNode.canDeploy(checkVerificationForXYZService).then(() => { ^ TypeError: pactNode.canDeploy is not a function at Object.<anonymous> (/var/lib/jenkins/workspace/ps_search-app_PR-746/Service/checkProviderVerification/canDeploy.js:16:14) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:17:47 [Pipeline] } [Pipeline] // dir [Pipeline] echo ? There are test failures, aborting build``` Getting above error in jenkins pipeline while running command `node canDeploy.js` , Any idea what is the cause of it?

tausif2909
2022-01-21 05:15
```/* global console */ // The tests below checks if services used by search app have passed the pact verification on https://pact.myportal.net/ or not // If the verification passes then we can deploy but if it fails , we should not go ahead with the build // as contract test validation is failed by provider const pactNode = require('@pact-foundation/pact-node'); // Checking pact verification done by XYZ service const checkVerificationForXYZ = { pacticipant: ['flex-abc-service', 'flex-pqr-app'], pacticipantVersion: ['1.0.0', '1.0.0'], pactBroker: 'https://pact.myportal.net/' }; pactNode.canDeploy(checkVerificationForXYZ).then(() => { console.log('PACT verification by xyz service is successful'); }).catch((err) => { console.log('Cannot deploy as pact verification failed against xyz service', err); abortDeploy(); }); // Checking pact verification done by search elastic service const checkVerificationForSearchElastic = { pacticipant: ['my-searchelastic-service', 'my-pqr-app'], pacticipantVersion: ['0.0.0', '1.0.0'], pactBroker: 'https://pact.myportal.net/' }; pactNode.canDeploy(checkVerificationForSearchElastic).then(() => { console.log('PACT verification by mty search elastic service is successful'); }).catch((err) => { console.log('Cannot deploy as pact verification failed against my search elastic service', err); abortDeploy(); }); function abortDeploy() { process.exit(1); }``` This is the code of `canDeploy.js` class

matt.fellows
2022-01-21 05:23
What version are you on?

tausif2909
2022-01-21 05:27
`"@pact-foundation/pact": "~10.0.0-beta.20",`

matt.fellows
2022-01-21 05:32
Which version of pact-node has that pulled in?

tausif2909
2022-01-21 05:34
in yarn.lock i can see : ```"@pact-foundation/pact-node@^6.4.1": version "6.18.3"```

tjones
2022-01-21 06:06
That's a *very* old version, and critically is before `canDeploy` was introduced

tjones
2022-01-21 06:06
(6.21.2), but really just upgrade to the latest (10.17.1)

tausif2909
2022-01-21 06:07
should I use : `const pactNode = require('@pact-foundation/pact-core')`; instead of const `pactCore = require('@pact-foundation/pact-node');`


tjones
2022-01-21 06:08
The best practice is to use the binstubs for the pact-broker binary

tjones
2022-01-21 06:09
you don't need your own script - having your own script increases the chance of bugs. For example, in your script, you have promises where the success is ignored. This might be a bug if your program terminates before the promises have resolved.

tjones
2022-01-21 06:10
You can see the options for `pact-broker can-i-deploy` here: https://github.com/pact-foundation/pact-ruby-standalone/releases

tjones
2022-01-21 06:10
you can use that CLI in your npm script - it is already installed by pact-js

tjones
2022-01-21 06:12
(You will need to upgrade your versions to the latest to get the binstubs - I can't remember where they were introduced, but it was definitely after 6.18.3)

tausif2909
2022-01-21 06:14
ok, will do, that is the existing implementation which is quite messed up and confusing on one of the service, I am refactoring it, so will reimplement with the latest version, thanks @tjones @matt.fellows

viveksingh.kiit
2022-01-21 09:29
has joined #pact-js

viveksingh.kiit
2022-01-21 09:57
@viveksingh.kiit has left the channel

james.demaine
2022-01-21 10:02
has joined #pact-js

theferryatbuckland
2022-01-21 20:24
has joined #pact-js

david.kormushoff
2022-01-22 00:54
has joined #pact-js

tom.tantisalidchai
2022-01-25 05:43
has joined #pact-js

cedric.spengler
2022-01-25 15:08
has joined #pact-js

austin.reifsteck
2022-01-25 15:20
has joined #pact-js

hsd999
2022-01-25 19:06
has joined #pact-js

parasonbe
2022-01-25 20:31
has joined #pact-js

alex.diaz
2022-01-26 09:05
has joined #pact-js

kskowron
2022-01-26 11:30
has joined #pact-js

spencerm
2022-01-26 14:33
has joined #pact-js

cristiano.cunha
2022-01-26 14:55
has joined #pact-js

cristiano.cunha
2022-01-26 15:50
Hi, I followed the workshop: https://github.com/pact-foundation/pact-workshop-js and was now trying to create the junit report with the console output (to have more details about each test), is it feasible? So far I got a _junit.xml_ created when I added a _jest.config.js_ file with the content: `module.exports = {` `reporters: [` `"default",` `["jest-junit", { outputDirectory: "test-results/jest" , includeConsoleOutput: true}],` `]` `};` But the "_includeConsoleOutput_" does not seem to have any effect. I also saw that with Junit we can have "_VerificationReports_" generated if we add the annotation "@_VerificationReports_" as explained here: https://docs.pact.io/implementation_guides/jvm/provider/junit/#enabling-additional-reports-via-annotations-on-the-test-classes. So, my question is can I generate the _VerificationReports_ or at least add the console logs to the Junit report with Jest?

spencerm
2022-01-26 17:04
is this the best practice pattern for generating contracts for endpoints that have path params? i?m a bit confused by the use of specific ids used in the examples vs defining something as a parameter e.g `/items/{id}`

tjones
2022-01-26 22:18
`jest-junit` is just for producing junit compatible reports, I think?

tjones
2022-01-26 22:20
Since a jest test for provider verification would only be one test, I don't think you can do what you're asking for

tjones
2022-01-26 22:22
The provider verification will write to standard out, it's possible that jest-junit hooks `console` instead of standard out?

tjones
2022-01-26 22:23
That's what I would do, as you're describing a request for an item with that specific ID

tjones
2022-01-26 22:23
Pact is contract by example, not contract by spec, so you're not trying to describe all requests, just provide examples that cover all types of request

nish063
2022-01-27 02:42
has joined #pact-js

ingcmurcia
2022-01-27 04:41
has joined #pact-js

weijian.duan
2022-01-27 08:58
has joined #pact-js

spencerm
2022-01-27 09:24
Makes sense, thank you :slightly_smiling_face:

cristiano.cunha
2022-01-27 10:34
Thanks for the input @tjones, I just find that: A few caveats (due to breaking changes in jest): 1. You must have at least 2 test files in order for console output to be sent to jest-junit 2. You cannot set verbose to true in jests config As stated in the issue: https://github.com/jest-community/jest-junit/issues/45, so if you have two test files the INFO level log will appear in the Junit report. Tricky but for now I will work with that :)

tjones
2022-01-27 10:37
Ah, right. I'm not sure if you'll pick up the logs made by the underlying binaries (since they write to standard out directly), but anything with a `pact-js` / `pact-node` / `pact-core` version number in it writes to `console` and can be hooked.

abraham.gonzalez93
2022-01-27 10:39
has joined #pact-js

akanksha.sharma
2022-01-27 11:16
@matt.fellows, we are trying to add custom header in side consumer.spec.js file as per our api requirement but after executing it seems like we can't add custom header. Can you please provide me a way to add the custom header and without it we can't verify our API

tjones
2022-01-27 11:26
I think this is complaining that the header is not present in your actual request (so pact is working correctly here)

tjones
2022-01-27 11:27
set the channel topic: Questions and updates about Pact in JS/TS/node. See also #pact-js-development for contribution or development questions. All questions welcome!

akanksha.sharma
2022-01-27 12:19
Here we have added 3 header Content-Type, Authorization, Config-Origin but for Authorization and Content-Type its working perfectly but once we have included Config-Origin(Custom-Header) in the header section then it start throwing error. You can see it in the above image

akanksha.sharma
2022-01-27 12:19
is it true that we can not add header apart from Content-Length, Content-Type, Host, Accept-Encoding, User-Agent, Authorization, Connection, Version??


tjones
2022-01-27 12:20
What is happening here is that you have told pact to expect a header that you are not sending with the request

tjones
2022-01-27 12:20
so pact is failing the test, because it is missing that header

tjones
2022-01-27 12:20
the list of headers there is the list of headers it *did* receive

tjones
2022-01-27 12:21
Pact will compare the actual request you send to the expectation that you are configuring here

yousafn
2022-01-27 12:51
You can add any header in your pact request interaction. However for the pact test to pass, your client code must include that header in its request it makes to the provider. Otherwise you would generate a pact, which isn?t being honoured by the client producing it.

demna
2022-01-27 15:29
has joined #pact-js

mircea.ungureanu
2022-01-27 15:48
has joined #pact-js

nikhilwa84
2022-01-27 17:43
has joined #pact-js

bogdanm.rusu
2022-01-27 18:04
has joined #pact-js

cventcport
2022-01-27 22:29
has joined #pact-js

mayuri.khemani
2022-01-28 09:43
has joined #pact-js

sujith.nair2
2022-01-28 12:33
has joined #pact-js

akanksha.sharma
2022-01-28 14:09
Hi, my contract testing project is working fine when it is present in C drive with a short path but as soon as the path length increase in C drive, it stop working. Can someone tell me the reason behind this.

rob
2022-01-28 16:36
has joined #pact-js

ben.watts
2022-01-28 17:22
:wave: Hello pact-js-ers, I'm getting the following error `connect EADDRNOTAVAIL ::1:43703 - Local (:::0)` in CI. Details on my situation: ? That 43703 number changes every time I run the job. (I assume it's a port) ? I'm running providers tests through nestsjs-pact. ? "pact_foundation/pact": "^9.17.2", ? "nestjs-pact": "^2.1.1", ? It's happening for me in CircleCI, but not locally. ? Docker image: cimg/node:14.17.5 ? I've been able to successfully setup provider tests in ruby in CircleCI, as well as consumer JS tests, so I'm quite confused here. In the 'how to ask a question' - it's advised to supply a minimum reproducible example - really not sure how to begin with that here, but would appreciate any advice. I really appreciate any support here!


matt.fellows
2022-01-28 22:05
We spin up a local proxy server as part of the test infra. It looks like it's resolving that as an ipv6 address. Try changing `localhost` in your setup to something like `127.0.0.1`

matt.fellows
2022-01-28 22:06
Any logs would also help

ben.watts
2022-01-28 23:25
Is there an option to change the host? I'm not seeing it - I'm looking at `@pact_foundation/pact/src/dsl/verifier.d.ts` for the list of options. I'm using nestjs_pact, looks like it https://github.com/omermorad/nestjs-pact/blob/master/src/interfaces/pact-provider-module-options.interface.ts 'providerBaseUrl' as an allowed option. See attached logs.

radovan
2022-01-29 00:20
has joined #pact-js

matt.fellows
2022-01-29 22:42
My apologies, I was on mobile when I answered and yes, this is a provider test so you can?t do that

matt.fellows
2022-01-29 22:44
ok so that log helped a bit. I suspect it?s a nestjs issue

matt.fellows
2022-01-29 22:44
I can see `http://localhost:33609/_pactSetup` in the log, that?s actually the proxy server setup by `@pact-foundation/pact` and it seems to have started just fine, because it successfully sent a respose

matt.fellows
2022-01-29 22:45
I?m guessing `41349` is the actual service port, because it seems to be where the actual target request is being sent (i.e. the test for an interaction against your provider)

matt.fellows
2022-01-29 22:45
Might be worth raising an issue on the nest pact repo?

matt.fellows
2022-01-29 22:45
I?m sorry, I can?t see much more - I don?t know NestJS or the test project

mongeyc
2022-01-31 14:03
has joined #pact-js

ben.watts
2022-01-31 16:34
Okay, great, thanks for helping triage! I'll return to this thread once I find out more.

mike.bernard
2022-01-31 21:14
has joined #pact-js

tjoy
2022-02-01 02:06
has joined #pact-js

max.tilford
2022-02-01 03:17
has joined #pact-js

toanshukumar
2022-02-01 14:15
has joined #pact-js

juanquis419
2022-02-01 15:01
has joined #pact-js

matt.murray
2022-02-01 19:40
has joined #pact-js

frederic.gendebien
2022-02-02 08:54
has joined #pact-js

dougie.robertson
2022-02-02 11:15
has joined #pact-js

juan.avendano
2022-02-02 13:36
has joined #pact-js


tjones
2022-02-03 07:41
I don't know nest-js very well (at all), but I think the reason that adapter exists is to make Pact fit more idomatically within the nest ecosystem

tjones
2022-02-03 07:41
it might be better to update the wrapper to make that option the default, and give the user the ability to override it

tjones
2022-02-03 07:41
@omer.moradd might be able to shed some light on what is happening

ausachov
2022-02-03 13:15
has joined #pact-js

aaron.kibbie
2022-02-03 15:59
has joined #pact-js

williangldzn
2022-02-03 20:23
has joined #pact-js

ricardo.gonzaga
2022-02-04 09:35
has joined #pact-js

robin.jacques
2022-02-04 10:51
has joined #pact-js

joaomiguel.rocha
2022-02-04 17:40
has joined #pact-js

jacek.sienniak
2022-02-07 08:45
has joined #pact-js

jamie.weatherby
2022-02-07 15:25
has joined #pact-js

theferryatbuckland
2022-02-07 15:37
Hello, I'm following the pact-workshop-js on Windows 10. I forked the project into my own repo, ran `npm install`, and was able to complete step 1. I'm trying step2, I did "git checkout step2" and step 2 seems to have loaded fine. However, when running "npm test --prefix consumer", I get this error: `> CI=true react-scripts test` `'CI' is not recognized as an internal or external command,` `operable program or batch file.` `npm ERR! Test failed. See above for more details.`

joaobrandao.rodrigues
2022-02-07 16:30
has joined #pact-js

ben.watts
2022-02-07 16:44
Yeah, unfortunately, I'm a bit new to nestjs as well, so there's a limited amount of troubleshooting I can do .

theferryatbuckland
2022-02-07 17:02
I'm just wondering if there are additional config changes that need to be made to the package.json to run on windows?

extra
2022-02-07 21:31
has joined #pact-js

matt.fellows
2022-02-07 21:33
ah, that?s because the script is prefixed with `CI=true` to set the env var inline

matt.fellows
2022-02-07 21:55
Did you want to see if https://www.npmjs.com/package/cross-env helps?

matt.fellows
2022-02-07 21:55
if it does, I?d accept a PR to use that so that it?s more portable?

matt.fellows
2022-02-07 21:56
I think you could then replace it with `cross-env CI=true react-scripts ?.` type thing

uglyog
2022-02-07 21:56
You can also run the commands using Bash

matt.fellows
2022-02-07 21:56
does windows 10 come with WSL?

mike.bernard
2022-02-07 21:57
:wave: I've hit somewhat of a roadblock in implementation. I've created provider tests for an AWS API Gateway application and I've been invoking the API directly in the tests, adding the proper authentication headers to each request. When using aws sig4 to sign requests, if the API requires a body, the signature must also include the body of the request. I'm looking for a way to intercept the body from each consumer pact and grab it to add to the signature. I'm currently using the `requestFilter` to intercept each request and add the auth to the headers, but the request object passed in doesn't contain a body. I've attempted to use SAM CLI to host the API gateway (to bypass auth) but it seems the way we've structured our stacks, the automated `sam local start-api` command can't find the lambda functions that we tie to each api. Only other way to use SAM afaik is to hardcode each endpoint into the template.yaml file, and include each request/response model, which isn't viable for our teams to do. TIA!


uglyog
2022-02-07 21:59
WSL will need to be enabled and Ubuntu image installed

theferryatbuckland
2022-02-07 22:50
Thanks guys, just now saw your replies. Sorry it's taken so long. I'll review all of your replies and let you know how it goes. I did find that I needed some React updates, so I've applied those. I probably won't get back till tomorrow some time. Thanks!

theferryatbuckland
2022-02-07 22:53
@uglyog Yes, I've been doing this in Git Bash, I always run my VSCode with that as the terminal.

uglyog
2022-02-07 22:54
Ah! Damn, it means the npm steps are not using bash

theferryatbuckland
2022-02-07 22:58
Really?

theferryatbuckland
2022-02-07 22:58
It runs fine when I do "npm start....", etc.

theferryatbuckland
2022-02-07 22:59
Also, I've run the tests on the individual consumer and provider samples at the Git root (not the work shop ones). Those tests worked fine, after a couple of tweaks.

theferryatbuckland
2022-02-07 23:01
Yeah, so the other Consumer example does have "cross-env CI=true react-scripts test", and that works in that example (no WSL, etc.).

theferryatbuckland
2022-02-07 23:02
But if I paste that into the Consumer sample embedded in the js workshop, it does not work - I get "cross-env" is not recognized as an internal command, etc.

theferryatbuckland
2022-02-07 23:04
I've also done npm install, just hoping it missed something, it updates, but no change to the behavior.

theferryatbuckland
2022-02-07 23:07
doing npm install again actually breaks a lot of stuff.

matt.fellows
2022-02-07 23:07
did you add `cross-env` to the project?s dependencies?

theferryatbuckland
2022-02-07 23:08
Nope, not there. I'm going to nuke my local and recheck-out, try again.

theferryatbuckland
2022-02-07 23:08
But now dinner's ready!

matt.fellows
2022-02-07 23:08
haha

matt.fellows
2022-02-07 23:08
ok

matt.fellows
2022-02-07 23:08
My point above was you could try adding the package and using it - it?s not currently part of the project

matt.fellows
2022-02-07 23:09
i.e. you?d need to `npm i --save-dev cross-env` and then modify the scripts accordingly

matt.fellows
2022-02-07 23:09
if you?re manually cd?ing into consumer/provider, don?t run `npm i` run `npm ci`

matt.fellows
2022-02-07 23:10
if you?re running the commands from the project root, `npm i` should work. But as a general rule, use `npm ci`

elenatuzel
2022-02-08 08:27
has joined #pact-js

vadim
2022-02-08 09:19
has joined #pact-js

anna.khv
2022-02-08 12:19
has joined #pact-js

dhospital
2022-02-08 16:15
has joined #pact-js

jcabrera
2022-02-08 18:26
has joined #pact-js

yousafn
2022-02-08 18:53
Hey buddy I used something similar to this on my client site https://github.com/YOU54F/jest-pact-typescript/blob/master/src/pact/verifier/verify.ts I had the same issue as you, there is an open feature request on pact js GitHub issues and @bernardo.guerreiro did a really good medium article on a bit of a workaround, I?ll find a link


yousafn
2022-02-08 18:58
https://medium.com/dazn-tech/pact-contract-testing-dealing-with-authentication-on-the-provider-51fd46fdaa78 Basically you pull the pact down prior and get access to the pact object beforehand and you can monkey patch your requests, with the obvious caveats before passing them to a verifier

mike.bernard
2022-02-08 19:23
@yousafn this is excellent! The medium article workaround isn't viable but I can try looking into v3 as suggested in that Github Issue. Thanks for the help!

yousafn
2022-02-08 19:54
No worries Mike :) Just reread the issue, will set myself a reminder to update the main post with a summary of discussion and clearly distinguish that it?s a v2 issue and point to an example of it working in v3 :)

mike.bernard
2022-02-08 20:18
I'm attempting to get it working with v3 right now. If you come across an example of it, feel free to drop it here. I'm also happy to add my code as an example on that github issue once i get it working :slightly_smiling_face:

mike.bernard
2022-02-08 20:54
@yousafn No luck with v3. When I attempt to use the requestFilters property and return an object like the documentation suggests, it fails. It really wants the `next` callback to be executed.

mike.bernard
2022-02-08 21:08
The last option i'm holding in my back pocket is to make a request to the pact broker myself and parse out any request bodies there and sign with them within each state handler.

yousafn
2022-02-08 23:30
Yeah just had a quick play with v3 and still not able to access the incoming body, I may be able to overwrite it, but as yourself for our use case, we needed to access the request body to send it in the AWS v4 sig request to get the appropriate headers. I did indeed choose the latter option that is in your back pocket to get round it on our account. I have to say I do like the v3 interface. Will take a delve further when I get a bit more time. Good luck buddy

ardiel.fuentes
2022-02-09 07:14
has joined #pact-js

ruud.von.faber
2022-02-09 09:11
has joined #pact-js

agustin.gomes
2022-02-09 13:23
has joined #pact-js

theferryatbuckland
2022-02-09 13:27
FYI, sorry, having to be on customer site yesterday, I'll try these out today at some time, I hope.

thijme.langelaar
2022-02-09 13:29
has joined #pact-js

dharmesh.kumar
2022-02-09 13:52
has joined #pact-js

mike.bernard
2022-02-09 13:55
Sounds good. Thanks so much for the help @yousafn!

theferryatbuckland
2022-02-09 14:10
Okay, I was able to make the changes to the package.json file, added "cross-env" to the "test" value, and the dependency, etc. I was also able to download/install "cross-env", though it worked by being at the workshop root (i.e., not cd'd into the consumer path). I was able to complete step 2. I'm going to experiment a bit, and maybe try that WSL option as well, though I wanted it to work as expected on straight windows, etc.

theferryatbuckland
2022-02-09 14:10
Thanks for the guidance!

theferryatbuckland
2022-02-09 14:10
I wonder if the workshop could be updated to include some instructions for this case?

athaper
2022-02-09 14:14
has joined #pact-js

svranyes
2022-02-09 20:16
has joined #pact-js

samuel.whittaker
2022-02-09 23:40
has joined #pact-js

uladzislau_danilchyk
2022-02-10 09:21
Hi everyone! Is there any possibility to set given section (provider state) multiple time (multiple provider states)? I tried to use V3 version but it's not implemented there. Could anyone help me with that? It's really very let's say critical thing for us.

david.hvilava
2022-02-10 10:53
has joined #pact-js

dharmesh.kumar
2022-02-10 13:17
Hello, How I can use *form-data/x-www-form-urlencoded/binary* data inside my consumer interaction (basically during creation of interaction and in client.js), can you please provide me some example or reference document .

uladzislau_danilchyk
2022-02-10 14:18
Hi everyone! I have an interaction with added headers and cookies. Example presented below. But I got an error like `Expected "XSRF-TOKEN=test-csrf-token" but got "undefined" at $.headers.Cookie` `Could not find key "X-XSRF-TOKEN" (keys present are: Content-Length, Content-Type, Accept, Cookie, X-Assess-Authenticated, User-Agent, Accept-Encoding, Connection, Host, Version) at $.headers`

uladzislau_danilchyk
2022-02-10 14:19
example: ```.withRequest({ path: '/graphql', method: 'POST', headers: { Cookie: 'XSRF-TOKEN=test-csrf-token', 'X-XSRF-TOKEN': 'test-csrf-token', }, })```

carlos.ferrao
2022-02-10 15:46
has joined #pact-js

rios.martinivan
2022-02-10 20:18
has joined #pact-js

francislainy.campos
2022-02-10 20:37
Hi, I have this contract done in Javascript: ```{ "consumer": { "name": "Ed UI" }, "provider": { "name": "Viaduct" }, "interactions": [ { "description": "A POST request to encode a JSON body of claims from the user", "providerState": "viaductService encodes a JSON body of claims and returns a JWT string in response", "request": { "method": "POST", "path": "/edcore/viaduct-service/jwt", "body": { "resourceId": "l_fc3ae9ed-62ac-4b94-8094-8dd29bc208a7_c57760a9-447b-42aa-81df-830134425157", "teacherAssessmentId": "93a91981-c6f7-435f-ab1e-80588ecff2ee", "expiryUnixEpochSeconds": 26757854170066, "sub": "UniqueUserId" } }, "response": { "status": 200, "body": "eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla", "matchingRules": { "$.body": { "match": "type" } } } }, ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }``` However, our provider tests (Java) fail with `Expected body 'eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla' to match 'eyJhbGciOiJIUzI1NiJ9.eyJzd.bla' using equality but did not match` . Not sure where the issue could be coming from. Initially I thought it might be related to the headers blocking the matchers as per https://stackoverflow.com/a/61924547/6654475, but even manually deleting the headers from the contract still give us the same issue, so maybe version related perhaps? `<pact.version>4.3.2</pact.version>` Thank you. CC @uglyog

charles.kuo
2022-02-10 21:42
has joined #pact-js

uglyog
2022-02-10 21:54
Can you raise an issue for this, it looks like a bug

uglyog
2022-02-10 21:55
Oh, I think the issue is the response is missing a content type header

uglyog
2022-02-10 21:55
So it is treating it as text, and not using the type matcher

theferryatbuckland
2022-02-10 22:02
@matt.fellows Just a note - on my Windows 10 laptop at least, running "ci" does not work, only "i". I've tried it a number of times/ways, and ci is not doing it. Thanks!

brentbarker9
2022-02-11 00:27
Hi, are there plans to allow a consumer project pass in parameters in it's state (state with-data) for the provider to use to setup it's state? Specifically calling out this feature in pact-jvm: ``` @State("with-data") // Method will be run before testing interactions that require "with-data" state public void toStateWithData(Map data) { // Prepare service before interaction that require "with-data" state. The provider state data will be passed // in the data parameter // ... System.out.println("Now service in state using data " + data); }``` https://github.com/pact-foundation/pact-jvm/tree/master/provider/junit#example-of-http-test



matt.fellows
2022-02-11 02:10
(that uses separate provider side feature, but you can see in the consumer test defines the data)


matt.fellows
2022-02-11 02:11
Note the usual warnings about beta etc.

matt.fellows
2022-02-11 02:11
we were a bit stalled on this release based on issues in an upstream package, but that?s unblocked now

matt.fellows
2022-02-11 02:11
so a new beta should be out soon that starts to get closer to the next major release

matt.fellows
2022-02-11 02:12
as in `npm ci` doesn?t work on Windows? what?s the problem?

matt.fellows
2022-02-11 02:12
`ci` says ?install exactly the versions of the dependencies in the lock file? where as `i` says: ?install the latest version of every package in the package.json using the semver specified dependency rules?

matt.fellows
2022-02-11 02:13
> I wonder if the workshop could be updated to include some instructions for this case? Agreed! If you have cross-env working already, we?d appreciate a PR that adds it in and I?ll get it in so others can benefit?

abubics
2022-02-11 04:49
Even if it's a kludge (for now?) you should be able to implement reusable provider state, based on the state string (if that's all you have available). The most structured pre-state*s* thing I've seen is a known format for the state string, which can be parsed out on the provider side, e.g. `"state A, state B, state C"` which becomes `['state A', 'state B', 'state C']` , then you can manually trigger those states. Not ideal, but the closest I've seen if you don't have library support.

francislainy.campos
2022-02-11 05:04
Sorry, I have this but still: ```"request": { "method": "POST", "path": "/edcore/viaduct-service/jwt", "headers": { "Content-Type": "application/json", "accept": "application/json" }, "body": { "resourceId": "l_fc3ae9ed-62ac-4b94-8094-8dd29bc208a7_c57760a9-447b-42aa-81df-830134425157", "teacherAssessmentId": "93a91981-c6f7-435f-ab1e-80588ecff2ee", "expiryUnixEpochSeconds": 26757854170066, "sub": "UniqueUserId" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJWaWFkdWN0U2Vydm.blabla", "matchingRules": { "$.body": { "match": "type" } } }```

uglyog
2022-02-11 05:05
Let me see if I can reproduce it

sudhanshu.testing
2022-02-11 05:12
has joined #pact-js

uglyog
2022-02-11 05:34
Works fine for me. I can see ```16:33:29.216 [DEBUG] [au.com.dius.pact.core.matchers.JsonBodyMatcher] compareValues: Matcher defined for path [$] 16:33:29.216 [DEBUG] [au.com.dius.pact.core.matchers.MatcherExecutor] comparing type of "eyJhbGciOiJIUzI1NiJ9.eyJzd.bla" to "eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla" at [$]```

uglyog
2022-02-11 05:35
That is with version 4.1.34, let me try 4.3.x

uglyog
2022-02-11 06:14
4.3.5 works fine for me. I can't reproduce this. I did have to change the response to ```"body": "\"eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla\"",```

uglyog
2022-02-11 06:14
But I did not get your error. Can you confirm the version of Pact-JVM?

francislainy.campos
2022-02-11 06:20
```<pact.version>4.3.2</pact.version>```

akke.luukkonen
2022-02-11 07:10
I've used simply the word `and` myself to split my V2 state string into multiple separate states, which are applied simultaneously. Not ideal as well, but at least it has worked great. I also added a separate `clean` (default: `true`) option in the request to specify whether the database is dropped before the requested state is applied. So I can sequentially apply states in non-Pact tests (integration, e2e).

francislainy.campos
2022-02-11 11:03
We may try to change the backend to return a json with the {} , but I think we may have got into a limitation for pact here, so it may be interesting to know if that?s really the case.

alessandro.polidori
2022-02-11 15:02
has joined #pact-js

theferryatbuckland
2022-02-11 15:42
I've never done a pull request. Should I do that at the pact-foundation level, or on my fork?

theferryatbuckland
2022-02-11 15:55
So, I made the change only to Step 2, and pushed to my fork. Now, I can see "This branch is 1 step ahead of pact-foundation:step 2". And under "Contribute", I see the option to "Open pull request".

theferryatbuckland
2022-02-11 15:59
Just looking for the steps to take from that point....

theferryatbuckland
2022-02-11 16:07
Also, just to clarify - the four files updated were the root "package.json" and "package-lock.json" and the "consumer/package.json" and "consumer/package-lock.json". They are all dependency references, etc.

theferryatbuckland
2022-02-11 16:08
Let me know if you want me to proceed. And if so, is there a way to do this all at once for each of the Step branches, etc.? Or would I have to do that for each of them?

theferryatbuckland
2022-02-11 18:36
I did a test pull request for Step 3, had to add cross-env to two locations in package. I'll hold off on any more till I hear back from you.

theferryatbuckland
2022-02-11 18:50
Yeah, and so with Step 4, I tried the "npm ci...." 2x, did not add cross-env. Did it with "npm c...." and it loaded fine. Odd.

theferryatbuckland
2022-02-11 19:29
For Step 4, when running test on the Provider, I'm getting this error:

theferryatbuckland
2022-02-11 19:29
"E:/Training/Pact.io/Pacit.io Demos/pact-workshop-js/provider/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.63/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.35.1/lib/pact/provider_verifier/app.rb:3:in `require': cannot load such file -- pact/provider_verifier/provider_states/add_provider_states_header (LoadError)"


theferryatbuckland
2022-02-11 19:55
Implementing the expanded path length in Windows did not work, but I was able to move to a shallower path, and that is working.

theferryatbuckland
2022-02-11 19:56
I did notice your comment from May 24, 2021, that the v3 branch would resolve this. Is that available yet, or merged into master, etc.?

theferryatbuckland
2022-02-11 23:08
Actually, is there a way to undo my pull request? I'd like to submit it a different way. I've read something about reverting from an already committed branch, or rebasing, etc. That's one reason I wanted someone from Pact to do the update, I'm still too new at this. Thanks!

krisakins
2022-02-12 20:19
has joined #pact-js

ian.cervantez
2022-02-13 03:32
has joined #pact-js

matt.fellows
2022-02-13 07:53
I'll review tomorrow and come back to you. The main thing was to get you the commit/contribution credit, but all good if you'd like us to address it!

matt.fellows
2022-02-13 07:54
(the change committed to one step won't automatically work in another step, you'll need to merge the code into all steps. Again, we can do if easier)

matt.fellows
2022-02-14 01:04
The current workshop is designed for the main/stable release. If you want to use the V3 release you can, it?s back under active development after being blocked by some upstream issues.

matt.fellows
2022-02-14 01:05
https://github.com/pact-foundation/pact-js#pact-js-v3 The workshop will be helpful in understanding the concepts, but there will be some minor differences in APIs.

matt.fellows
2022-02-14 01:06
> Let me know if you want me to proceed. And if so, is there a way to do this all at once for each of the Step branches, etc.? Or would I have to do that for each of them? Ah, yes. We?ll need them in all steps. It?s a bit of a pain in the butt. I tend to get a single branch working first, and then cherry-pick each commit into separate branches (see e.g. https://github.com/pact-foundation/pact-workshop-js/blob/master/consumer/scripts/update-branches.sh to do so)

antonio.gamiz
2022-02-14 06:51
has joined #pact-js

theferryatbuckland
2022-02-14 13:20
I'm thinking the best thing is to reject the Step 3 pull request, and I should have just updated the ReadMe file (near the beginning) on the main page, just instructions for anyone that has that error. Should not have updated the code.

zish.gatrad
2022-02-14 16:01
has joined #pact-js

james.troughton
2022-02-14 16:08
has joined #pact-js

brentbarker9
2022-02-14 20:39
Thank you Matt!

manuelam20
2022-02-15 00:41
has joined #pact-js

dchen
2022-02-15 08:03
has joined #pact-js

aristides.suarez
2022-02-15 08:14
has joined #pact-js

marcelino.garcia
2022-02-15 08:22
has joined #pact-js

varnika.singh
2022-02-15 09:11
has joined #pact-js

edouard.lopez
2022-02-15 10:59
In the README I see interaction declare using a literal object `provider.addInteraction({state:?, uponReceiving:?})` and in the typescript example you use an instance of `new Interaction()` . Do you have recommendation for each approach?

matt.fellows
2022-02-15 11:20
Some people prefer the OO based and some prefer passing JSON. They are the same thing, so it comes down to personal preference

dharmesh.kumar
2022-02-15 14:25
@matt.fellows I am using matcher to match one properties that can have value null most of the time or any string so how I can write the expected response body of consumer `"description":term(` `generate: null,` `matcher: /([a-z])|null/),` I have written this it throwing error. can you please help me to resolve it.

bernard
2022-02-15 16:22
has joined #pact-js

david.uzumaki
2022-02-15 16:33
has joined #pact-js

abhishekc.jh
2022-02-15 17:21
has joined #pact-js

nuno.frias
2022-02-15 19:28
has joined #pact-js

matt.fellows
2022-02-15 21:28
You can?t do that

matt.fellows
2022-02-15 21:29
`null` is a type, not a string. So you can?t apply a regex to it


matt.fellows
2022-02-15 21:29
you need to create two scenarios - one for each

matt.fellows
2022-02-15 21:30
Also, for future reference, please don?t `@` people directly unless requested. We already monitor most channels and if we?re not responding it?s usually because we?re asleep :slightly_smiling_face:

faran
2022-02-15 22:31
has joined #pact-js

andy
2022-02-16 00:35
has joined #pact-js

fushinoryuu
2022-02-16 01:40
has joined #pact-js

dharmesh.kumar
2022-02-16 05:23
Thanks

abdelior
2022-02-16 08:48
has joined #pact-js

misterjkl
2022-02-16 13:12
has joined #pact-js

brian.azizi
2022-02-16 14:05
has joined #pact-js

richelle.raaphorst
2022-02-16 15:17
has joined #pact-js

tjones
2022-02-17 13:30
@tjones has left the channel

guillermo.aguirre
2022-02-17 20:06
has joined #pact-js

tati.shep
2022-02-18 06:52
has joined #pact-js

adamslack
2022-02-18 15:55
has joined #pact-js

darwin.cahyadi
2022-02-18 18:00
has joined #pact-js

jkdihenkar
2022-02-19 10:50
@jkdihenkar has left the channel

rishi.speets
2022-02-19 14:43
has joined #pact-js

ybergstrom
2022-02-21 03:24
has joined #pact-js

gyuvaraj10
2022-02-21 08:03
has joined #pact-js

athissen
2022-02-21 08:09
has joined #pact-js

mike.geeves064
2022-02-21 09:36
More of a general JS question than Pact specifically. I'm pretty new to JS so pretty much zero experience testing with it. Are there any general preferences of Jest vs Mocha? (or anything else?). With a focus on nice with Pact ofc, if there are any preferences of working with one over the other. I'm currently working with Vue3+Quasar, bdd makes me happy :grinning:

matt.fellows
2022-02-21 09:36
I think jest is the current most used due primarily to react

matt.fellows
2022-02-21 09:37
Tim recently released a mocha interface for Pact which matches the jest pact functionality

mike.geeves064
2022-02-21 09:37
Yeah, I saw mocha examples in there :thinking_face:

mike.geeves064
2022-02-21 09:37
React, Jest, FB eugh

matt.fellows
2022-02-21 09:38
I don't know if they use the new mocha specific library or just mocha directly

mike.geeves064
2022-02-21 09:50
Do you know if that was because fun or much demand? :thinking_face:

matt.fellows
2022-02-21 09:53
Mocha is pretty popular (by downloads) but I?d say the majority start with Jest.

yousafn
2022-02-21 10:17
Mocha is an incredibly popular and powerful testing framework and has been around for many many years. Jest has been gaining in popularity and traction for many reasons, but part of its explosion was around it being bundled with create react app out of the box. I remember when it first came onto the scene, we have cheat sheets between mocha and jest examples to help people transition. Also Mocha/chai is used as the assertion engine in several bigger tools aswell, such as Cypress. So I wouldn?t discount support for one of the other.

matt.fellows
2022-02-21 10:18
FWIW I use mocha by default - it goes nice with Chai :slightly_smiling_face:

matt.fellows
2022-02-21 10:18
(personally, I like the combination of chai+mocha, the fluent assertions are really nice). I found Jest awkward, but have accepted it?s the most used

andrefcsousa
2022-02-21 10:19
has joined #pact-js

katharina.pavic
2022-02-21 12:37
has joined #pact-js

mike.geeves064
2022-02-21 12:53
Mocha sounds like maybe better, especially if going towards cypress as well then?

mike.geeves064
2022-02-21 12:53
Sounds good, I will give mocha a try then, thanks! :grinning:

mike.geeves064
2022-02-21 12:54
I do prefer the names but it didn't seem like a good reason for choice in itself :joy:

mike.geeves064
2022-02-21 13:43
I do like a chai steamer from AMT

mike.geeves064
2022-02-21 13:43
:coffee::coffee::coffee:

mike.geeves064
2022-02-21 13:44
@yousafn Need to pick one or the other, at least with which to try out first :slightly_smiling_face: so much to read. Also I'm behind schedule, this was needed to measure when I need to water my plants as in away this week but it wasn't quite ready in time :joy::joy:

ipoe
2022-02-21 14:54
has joined #pact-js

abatan.k
2022-02-21 15:47
Hello all :) is there a binding for deno ?

jeroen.vandijk
2022-02-21 16:40
has joined #pact-js

yousafn
2022-02-21 16:43
These are some decent cheat sheets out there https://gist.github.com/yoavniran/1e3b0162e1545055429e So mocha is a test runner chai is an assertion engine sinon is used for mocking lolex for date/time mocking everyone used mocha as the test runner and then plugged in whatever they needed. Jest provides a runner, with an assertion engine built in. They are nearly the same with some caveats. the cheat sheets will help massively If you were using a create-react-app I would suggest jest-pact as jest ships out the box with cra. both have good support, Mocha has been around for like eons compared to Jest, so is very robust by now. I switch projects to jest now, unless they are deeply embedded, because it keeps the backend and front end unit testing frameworks the same :thumbsup:

yousafn
2022-02-21 16:44
mocha+chai or jest. Personally just go for jest, it will have everything you need out the box, need to reduce that cognitive load hehe

mike.geeves064
2022-02-21 17:20
Nod. I ofc have to go for something a little less mainstream so skipped react :grinning:

mike.geeves064
2022-02-21 17:22
Ahh names. My BE is going to be python You wouldn't mocha for the BE? I did not see that :thinking_face:

mike.geeves064
2022-02-21 17:27
Hmm interesting about switching projects :thinking_face: that would make sense if you have two different and could have two the same though

yousafn
2022-02-21 17:30
last project where I got introduced to Jest, it was TypeScript across the board. Mocha is JS land, so you would pick a suitable testing framework for Python. I think https://docs.pytest.org/en/7.0.x/ is most peoples go to. We wrote a few python scripts and used https://github.com/spulec/moto to mock out aws services

mike.geeves064
2022-02-21 17:32
Yeah I've got python covered, JS is the new land :grinning:

mike.geeves064
2022-02-21 17:35
Can you folk do BDD yet? :grinning:

mike.geeves064
2022-02-21 17:35
Moto is insane. Mock an ec2 instance. What does that even mean :open_mouth::open_mouth:

yousafn
2022-02-21 17:36
Hello Carere! Very cool that you are asking, I have really enjoyed Deno and watching its journey I don?t believe so, I started messing about with deno a while back, and setup and consumer/provider example to start testing out pact, but didn?t as got distracted by other things https://github.com/YOU54F/deno-examples/blob/main/README.md Just did a quick google and this looks interesting https://deno.land/x/tribles@v0.6.2 the readme mentions pact, which is curious, not looked in any detail yet > So far the following components have been implemented. > ? PACT js implementation. > ? TribleDB js immutable trible database. > ? TribleKB js immutable trible knowledge-base. >

abatan.k
2022-02-21 19:20
Hello, thks for your reply, i checked the deno repo , but it is not about pact :slightly_smiling_face:

abatan.k
2022-02-21 19:21
I will look the implementation for nodejs and try to provide one for deno :slightly_smiling_face:

abatan.k
2022-02-21 20:00
@matt.fellows Hello :slightly_smiling_face: What should it takes to be able to do contract testing in deno ?? It seems that i can just call the binary in my code, instead of doing `new Verifier(...).verify()` ? Is there a proper way to implement a deno version of pact ??

ondikumana
2022-02-21 22:13
has joined #pact-js

ian.cervantez
2022-02-22 03:02
the auto-mock feature of jest is pretty awesome - but for pact testing basically useless.

nithyag.ganesan
2022-02-22 10:01
has joined #pact-js

ntiwari
2022-02-22 11:48
has joined #pact-js

phil.vint
2022-02-23 11:01
has joined #pact-js

phongthornk
2022-02-23 11:04
has joined #pact-js

lukasz
2022-02-23 14:55
has joined #pact-js

matt.fellows
2022-02-23 20:46
I haven't looked at deno for a while

matt.fellows
2022-02-23 20:48
You could call those binaries directly, yes, but we're moving to a rust core via shared libraries . The new v3 pact uses a C++ wrapper but I'm hopeful given deno is rust we'd be able to use rust directly to interface to JS

dharmesh.kumar
2022-02-24 10:31
Hi, How we can compare only schema of response in contract testing ?

athaper
2022-02-24 11:01
Hello! I?m having an issue with pact jest where my tests are passing but the pact isn?t being generated in the directory I?ve tried several possible solutions that we could find on google but nothing worked , can someone here help please ? attaching the spec file below

athaper
2022-02-24 11:01
```"use strict" const { Pact } = require("@pact-foundation/pact") const path = require('path'); const {eachLike} = require("@pact-foundation/pact/src/dsl/matchers"); const Constant = require("../src/Constant"); const API_HOST = "http://localhost:7000/dev/" const provider = new Pact({ consumer: 'portal-ui', provider: 'portal', port: 7000, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'DEBUG', }); describe('SiteSpeed Details Service', () => { describe('Wanted to get SiteSpeed Details', () => { beforeAll(() => provider.setup().then(() => { provider.addInteraction({ uponReceiving: 'a request to list sitespeed details', withRequest: { method: 'GET', path: API_HOST+'portal/v1/sitespeed/pages?executionId=4660', }, willRespondWith: { status: 200, body: eachLike( { execution_id: 4660, execution_page_id: 8207, first_contentful_paint_median: 6791, }, { min: 1 } ), }, }); }) ); it('should return the correct data', async() => { const sitespeed = await fetch(API_HOST+'sitespeed/pages?executionId=4660'); const response = await sitespeed.json(); expect(response[0].execution_id).toBe(4660); expect(response[0].execution_page_id).toBe(8207); }); afterEach(() => provider.verify()); afterAll(() => provider.finalize()); }); });```

abubics
2022-02-24 11:02
Like, flexible matching of the shape, or you have a schema defined and you want to verify it?

matt.fellows
2022-02-24 11:05
can you please share the `pact.log` and terminal output? It should show us there why it?s not working

matt.fellows
2022-02-24 11:06
btw the path looks incorrect to me, the query string should be moved into `query`

matt.fellows
2022-02-24 11:06
we could probably detect that case and warn

dharmesh.kumar
2022-02-24 11:07
yes Right, I have defined expected response and I want to verify only schema.

dharmesh.kumar
2022-02-24 11:08
I have also used the matcher but it does not full fill my requirement as it have some limitation with null value check.

athaper
2022-02-24 11:10
Here?s the pact.log file ```I, [2022-02-24T16:27:48.550621 #29652] INFO -- : Verifying - interactions matched I, [2022-02-24T16:27:48.552026 #29652] INFO -- : Registered expected interaction GET http://localhost:7000/dev/sitespeed/pages?executionId=4660 D, [2022-02-24T16:27:48.552434 #29652] DEBUG -- : { "description": "a request to list sitespeed details", "request": { "method": "GET", "path": "http://localhost:7000/dev/sitespeed/pages?executionId=4660" }, "response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::ArrayLike", "contents": { "execution_id": 4660, "execution_page_id": 8207, "first_contentful_paint_median": 6791, }, "min": 1 } }, "metadata": null } I, [2022-02-24T16:27:48.558270 #29652] INFO -- : Cleared interactions```

matt.fellows
2022-02-24 11:13
notice how there are no logs indicating it received a request from your client before the interactions are cleared? I suspect there is a promise mishandling going on

matt.fellows
2022-02-24 11:14
Is it possible something else is running on port 7000? ALso, the terminal output would be helpful please

athaper
2022-02-24 11:19
yes there was something else running on port 7000 , i closed it and reran the test but still no pact got generated Here?s the console output ```[2022-02-24 11:17:53.297 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Creating Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"} [2022-02-24 11:17:54.873 +0000] INFO (32372 on C02YQC2LLVCG): pact@9.17.2: Setting up Pact with Consumer "qe-portal-ui" and Provider "qe-portal" using mock service on Port: "7000" [2022-02-24 11:17:54.901 +0000] INFO (32372 on C02YQC2LLVCG): pact@9.17.2: Pact File Written [2022-02-24 11:17:54.902 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Removing Pact process with PID: 32539 [2022-02-24 11:17:54.910 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Deleting Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}```

athaper
2022-02-24 11:25
and here?s the console output with debug log level ```/Users/athaper/.asdf/shims/node --require /Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-stdin-fix.js /Users/athaper/Repo/qe-portal-ui/node_modules/jest/bin/jest.js --colors --reporters /Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-reporter.js --verbose --testNamePattern=^SiteSpeed Details Service --runTestsByPath /Users/athaper/Repo/qe-portal-ui/contract_tests/sitespeed_execution.spec.js [2022-02-24 11:20:16.971 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Creating Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"} [2022-02-24 11:20:16.993 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: Starting pact binary '/Users/athaper/Repo/qe-portal-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.81/pact/bin/pact-mock-service', with arguments [service --consumer qe-portal-ui --cors false --pact_dir /Users/athaper/Repo/qe-portal-ui/pacts --host 127.0.0.1 --log /Users/athaper/Repo/qe-portal-ui/logs/pact.log --log-level DEBUG --provider qe-portal --pact_specification_version 2 --ssl false --port 7000 --pact-file-write-mode overwrite] [2022-02-24 11:20:17.002 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: Created '/Users/athaper/Repo/qe-portal-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.81/pact/bin/pact-mock-service' process with PID: 32945 [2022-02-24 11:20:17.803 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2022-02-24 11:20:17.803 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO WEBrick::HTTPServer#start: pid=32945 port=7000 [2022-02-24 11:20:18.049 +0000] INFO (32777 on C02YQC2LLVCG): pact@9.17.2: Setting up Pact with Consumer "qe-portal-ui" and Provider "qe-portal" using mock service on Port: "7000" [2022-02-24 11:20:18.078 +0000] INFO (32777 on C02YQC2LLVCG): pact@9.17.2: Pact File Written [2022-02-24 11:20:18.078 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Removing Pact process with PID: 32945 [2022-02-24 11:20:18.083 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2022-02-24 11:20:18.084 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Deleting Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}```

matt.fellows
2022-02-24 11:38
and `/Users/athaper/Repo/qe-portal-ui/pacts` is empty?

athaper
2022-02-24 11:39
Yep!

matt.fellows
2022-02-24 11:40
strange

matt.fellows
2022-02-24 11:40
definitely no Ruby processes hanging about ```ps -ef | grep ruby```

athaper
2022-02-24 11:44
only seeing this one

athaper
2022-02-24 11:59
We?re using jest already for UTs and installed pact jest , is it possible that something might be conflicting ? Here are the dependencies in our package.json ``` "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^12.0.0", "autoprefixer": "^6.7.2", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^23.4.2", "babel-loader": "^8.0.0", "c3": "^0.4.23", "css-loader": "^0.26.1", "file-loader": "^0.10.1", "group-array": "^0.3.3", "history": "^5.0.0", "immutable": "^4.0.0-rc.12", "jest": "^27.0.6", "jest-pact": "^0.9.1",```

abubics
2022-02-25 00:42
The FAQ, especially https://docs.pact.io/faq/#why-is-there-no-support-for-specifying-optional-attributes addresses some of these concerns (and others).

abubics
2022-02-25 00:42
Pact is contract-by-example, not schema-by-spec, but I'm not sure if you're trying to do something Pact isn't meant for, or if it's just a vocabulary issue.

abubics
2022-02-25 00:43
If you genuinely want to do only schema validation, there are other tools, and you will lose a significant amount of reasoning power.

dharmesh.kumar
2022-02-25 05:29
Thanks

ezequiel.uhrig
2022-02-25 13:46
has joined #pact-js

emin.sahin
2022-02-26 13:53
has joined #pact-js

ihassin
2022-02-27 21:20
has joined #pact-js

yumiihuang
2022-02-28 09:55
has joined #pact-js

yousaf
2022-02-28 11:57
has joined #pact-js

gerry
2022-02-28 12:56
has joined #pact-js

agustina.bosso
2022-02-28 16:04
has joined #pact-js

alex.chabatarevich
2022-03-01 11:41
has joined #pact-js

luke.bickell
2022-03-01 14:46
has joined #pact-js

james.williams
2022-03-01 16:29
has joined #pact-js

qluck
2022-03-01 22:15
has joined #pact-js

qluck
2022-03-01 22:18
Hi everyone, I'm having an issue running a test that should be passing (and does on 10.0.0.beta54) after I've upgraded to 10.0.0.beta56. The issue is around the content-type header, and the error is `Expected body with content type application/json but was image/jpeg` . Can anyone please help?

qluck
2022-03-01 22:18
here's my code: ```const { pactWith } = require("jest-pact/v3"); const { MatchersV3 } = require("@pact-foundation/pact/v3"); const mockPactServerClient = require("../../utility/mockPactServer"); const fs = require("fs"); const { string } = MatchersV3; pactWith( { consumer: "bulk-upload", provider: "upload-provider", logLevel: 'INFO', port: 8081, }, (interaction) => { const fileBody = Buffer.from(fs.readFileSync("pikachu.png")).toString("base64"); interaction("initiateUpload", ({provider, execute}) => { beforeEach(() => provider .uponReceiving("Initiate Upload") .withRequest({ method: "PUT", path: '/bar/foo', headers: { Authorization: string("headerbar"), Accept: 'image/jpeg', 'Content-Type': 'image/jpeg', }, body: fileBody }) .willRespondWith({ status: 201 }) ); execute("Content-type bug test", () => { return mockPactServerClient.put( '/bar/foo', fileBody, { headers: { Authorization: "Bearer Auth", Accept: 'image/jpeg', "Content-Type": "image/jpeg", }, } ); }); } ) } );```

qluck
2022-03-01 22:19
what doesn't make sense is that I'm specifying the content type as `"image/jpeg"` everywhere, but it's still looking for `application/json`?

qluck
2022-03-01 22:29
here's the error

qluck
2022-03-01 22:29
```? Pact between bulk-upload and upload-provider ? with 30000 ms timeout for Pact ? initiateUpload ? Content-type bug test Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was incorrect: PUT /bar/foo 1.0 Expected body with content type application/json but was image/jpeg```

matt.fellows
2022-03-01 23:27
try setting the `contentType` property on the request and response bodies. That is part of the API I?m still looking at addressing. We?re in an awkward state where I?d like to continue support the JSON-like setup above, but it means certain options aren?t forced to be set. I?d prefer a type-state builder style API, but that won?t play nice with Jest Pact etc.

peter.pinda
2022-03-01 23:37
has joined #pact-js

peter.pinda
2022-03-02 00:22
Hi guys, Just wandering if anyone encounter the scenario, when multiple contacts on provider are fetched from broker (based on selector like tag:main, and deployed:true ). We need to reset our SQLite DB for each contract. Do you guys have any ideas how to do it:pray: ? `beforeEach` is triggered before each contract interaction so I probably cant use that one...

matt.fellows
2022-03-02 00:25
i?m not sure what the problem is you?re having Peter, could you please elaborate?

matt.fellows
2022-03-02 00:25
Provider states are usually how you handle different scenario data needs

peter.pinda
2022-03-02 00:45
Thanks @matt.fellows jumping into my issue... when we run:pact test on provider site, we spin the nextjs app module, create SQLighte db with data.Than Provider gets 2 contracts from PactFlow (based on selectors), first contract finds and deletes record in DB which passes ok, but for second which has same interactions, record is not found because first contact deleted it... If there is a way I can reset a DB between first and second contract I will probably solve my problem... PS: sorry tricky to explain

matt.fellows
2022-03-02 00:48
yes, you use provider states to specify ?thing exists? or ?thing does not exist? which triggers a provider state hook to fire. In htat hook (a JS function) you can manipulate the state of the interaction

matt.fellows
2022-03-02 00:48
see the e2e example in the Pact JS repository for a good example, or the JS workshop step :point_down: (howtolearn)

2022-03-02 00:48
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

peter.pinda
2022-03-02 01:11
hmm, for now we are using states for 2 users... like: ``` stateHandlers: { 'Agent login': async () => { token = getToken(jwtAgentData); }, 'Vendor login': async () => { token = getToken(jwtVendorData); }, },``` and on the consumer `given('Agent login')` ... Is there any way we can pass multiple states...lie `given(['Agent login', 'Clear some data'])` ?

matt.fellows
2022-03-02 01:22
Have a look at the docks there's a pre hook and post test hook. Personally I would just clear out the state for every provider state anyway so you always have a clean slate to begin with

peter.pinda
2022-03-02 02:02
@matt.fellows Appreciate you advice, thank you!

matt.fellows
2022-03-02 02:06
:+1:

omer.bilgin
2022-03-02 15:51
has joined #pact-js

qluck
2022-03-02 18:05
that helped!

qluck
2022-03-02 18:05
However, I'm running into another issue now with another test

qluck
2022-03-02 18:08
I have a custom contentType that I need to match, and whenever it's used i get the same error as above. The contentType is like this: `application/foo.bar.bulk-transfer+json` . Interestingly, if I don't use the "+" and change it to a "-", It will match. Something may be going on with matching "+" signs? A similar contentType is used in my company that I cannot change. Do you have any ideas on this? @matt.fellows

qluck
2022-03-02 18:09
here's an updated test: ```const { pactWith } = require("jest-pact/v3"); const { MatchersV3 } = require("@pact-foundation/pact/v3"); const mockPactServerClient = require("../../utility/mockPactServer"); const { string } = MatchersV3; pactWith( { consumer: "bulk-upload", provider: "upload-provider", logLevel: "INFO", port: 8081, }, (interaction) => { interaction("initiateUpload", ({ provider, execute }) => { beforeEach(() => provider .given("An experiance user") //These can share a state handler. However because we don't actually need to do anything, it's not needed in this case. .uponReceiving("A disallowed but allowed asset name") .withRequest({ method: "POST", path: "/bar/foo", headers: { Authorization: string("headerbar"), }, body: { "dc:format": "image/jpeg", }, contentType: 'application/foo.bar.bulk-transfer+json', }) .willRespondWith({ status: 200, headers: {}, body: { "dc:format": string("image/jpeg"), }, contentType: 'application/foo.bar.bulk-transfer+json', }) ); execute("Create Disallowed Asset", () => { return http://mockPactServerClient.post( "/bar/foo", { "dc:format": "image/jpeg", }, { headers: { Authorization: "Bearer Auth", "Content-Type": 'application/foo.bar.bulk-transfer+json', }, } ); }); }); } );```

banolik
2022-03-02 18:35
has joined #pact-js

thanuxxxx
2022-03-02 19:21
Hi, When we do a POST or PUT request for consumer tests, Is that possible to use temples to wrap the request body like this ```{ key1: string('value'), key2: number(1234) }```

matt.fellows
2022-03-02 21:23
What are you trying to do? You can probably just wrap what whole payload in a `like` matcher if you just want to check the shape

qluck
2022-03-02 21:52
if anyone has a similar issue as I've described above, I got it to work using regex

qluck
2022-03-02 21:52
remove the contentType property, and throw it back into the header.

qluck
2022-03-02 21:53
```"Content-Type": regex( /application\/vfoo.bar.bulk-transfer\+json/, "application/foo.bar.bulk-transfer+json"),``` This is what the regex will look like, and it will match on the incoming header from a request

qluck
2022-03-02 21:54
Note: the regex only needs to be put in the .withRequest,

ancyaziz
2022-03-02 22:26
has joined #pact-js

timothyg
2022-03-02 23:40
has joined #pact-js

timothyg
2022-03-02 23:56
Hello everyone, my team updated to version `10.0.0-beta.56` to get the timeout fix https://github.com/pact-foundation/pact-js/issues/761 We are running into an issue were the state handlers teardown is no longer being called. I don't see any change in the signature of the state handlers between `10.0.0-beta.54` and the version we are using now. Anyone have any ideas why the teardown isn't be executed? I'll include an example of the code in the thread.

timothyg
2022-03-02 23:57
Code Example: ```"State Handler": { resourceId: undefined, setup: async () => { console.log("Setup") resourceId = await setupState(); return Promise.resolve({ queryId: resourceId }); }, teardown: async () => { console.log('Teardown') await teardownState(resourceId); }, }```

mike.geeves064
2022-03-03 00:38
Not sure timelines of versions but there was a bug whereby the flag to tear down wasn't being used and *always* did a tear down, on the rust side during a verify: https://github.com/pact-foundation/pact-reference/pull/167 Iirc there's just a flag when calling the verifier to use them

mike.geeves064
2022-03-03 00:39
--state-change-teardown

harihararaj.lk
2022-03-03 09:44
has joined #pact-js

harihararaj.lk
2022-03-03 09:51
Hello people, Trying to do equality matching of the response body , but using Matcher doesn't provide any equality matching ability. Is there any workaround or am i missing something on the matcher ?? ```"matchingRules": { "$.body": { "match": "equality" } }```

matt.fellows
2022-03-03 10:57
can you please share your test details? If you just want to match the exact body, you don?t need to use a matcher - it?s effectively ?equality? by default

matt.fellows
2022-03-03 10:57
why do you want to do a strict match, may I ask?

harihararaj.lk
2022-03-03 11:06
@matt.fellows, we are using strict match because we are using the same set of data at both provider and consumer ends, and data matching is somewhat a requirement .

harihararaj.lk
2022-03-03 11:07
"interactions": [ { "description": "Request to save theme", "providerState": "Request to save themes", "request": { "method": "POST", "path": "/themes-service/save", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "results": [ { "name": "abc", "result": true } ] }, "matchingRules": { "$.body.: { "match": "type" } } } ]

harihararaj.lk
2022-03-03 11:09
we are using jest library to generate pact contract json files , which is not including the equality matching rule by default

matt.fellows
2022-03-03 11:10
I need to see your test please

matt.fellows
2022-03-03 11:10
my guess is you?re wrapping the body in a matcher such as `like`

matt.fellows
2022-03-03 11:10
just don?t use the matcher

harihararaj.lk
2022-03-03 11:13
```import { HTTPMethod } from "@pact-foundation/pact/src/common/request"; import { Matchers } from "@pact-foundation/pact"; import { pactWith } from "jest-pact"; import fetch from "node-fetch"; import { URL } from "url"; jest.setTimeout(30000); pactWith( { consumer: "aggregator", provider: "theme_provider" }, (provider) => { describe("Theme related end points", () => { it("Request to save themes", async () => { const url = new URL( `${provider.mockService.baseUrl}/themes-service/themes` ); const { validateExample } = Matchers; const interaction = { state: "Request to save themes", uponReceiving: "Request to save themes", withRequest: { method: http://HTTPMethod.POST, path: url.pathname, headers: { Accept: "application/json" }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json" }, body: { results: [{ handle: "abc", result: "Created" }], }, }, }; await provider.addInteraction(interaction); const result = await fetch( `${provider.mockService.baseUrl}/themes-service/themes`, { method: http://HTTPMethod.POST, headers: { Accept: "application/json", "Content-Type": "application/json", }, } ); expect(await result.json()).toEqual({ results: [ { handle: "abc", result: "Created", }, ], }); }); }); } );```

harihararaj.lk
2022-03-03 11:14
Yeah I had wrapped the entire body with *like* matcher because the generated pact json didn't have any matching rules when using the above

matt.fellows
2022-03-03 11:38
matching rules aren?t needed for exact match. Did that work?

harihararaj.lk
2022-03-03 11:43
@matt.fellows, No it didn't work. The generated pact json was as given below. It is passing at the consumer test , but when json is used by a provider (Spring boot application), it basically ignores the validation, as there are no matching rules condition. When manually the equality matching rule is added it is passing though

harihararaj.lk
2022-03-03 11:43
```{ "consumer": { "name": "aggregator" }, "provider": { "name": "theme_provider" }, "interactions": [ { "description": "Request to save themes", "providerState": "Request to save themes", "request": { "method": "POST", "path": "/themes-service/themes", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "results": [ { "handle": "abc", "result": "Created" } ] } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

matt.fellows
2022-03-03 11:51
> , but when json is used by a provider (Spring boot application), it basically ignores the validation, as there are no matching rules condition. When manually the equality matching rule is added it is passing though That?s not how it works, something else must be wrong. Can you please share the actual problem you?re having?

matt.fellows
2022-03-03 11:53
hm interesting

matt.fellows
2022-03-03 11:53
> , if I don?t use the ?+? and change it to a ?-?, It will match. Something may be going on with matching ?+? signs? smells of escaping or something doesn?t it.

matt.fellows
2022-03-03 11:54
If you could please set the log level to debug and provide an output dump, that would be helpful in seeing what the engine thinks is goinsg on

matt.fellows
2022-03-03 12:08
Hi Timothy! hmm, it should support them. Any chance you could please share a debug log for us to take a look at?

matt.fellows
2022-03-03 12:11
The change Mike contributed should be in the latest JS though

mike.geeves064
2022-03-03 12:11
The bug I looked at was it always sent them even without the flag, the logic meant it was always true, so maybe some backwards compatibility issue introduced

matt.fellows
2022-03-03 12:11
ah

mike.geeves064
2022-03-03 12:11
If it is related to that, I forgot to check this morning

mike.geeves064
2022-03-03 12:12
On mobile again :) the default was don't send, but the default didn't work

matt.fellows
2022-03-03 12:13
Actually, that handler definition looks incorrect to me

matt.fellows
2022-03-03 12:15
nvm, I?m tired.

matt.fellows
2022-03-03 12:15
I mean, there is a superfluous key there (`resourceId`) but that shouldn?t break things

mike.geeves064
2022-03-03 12:21
I think just calling pact-verifier with --state-change-teardown should do it, if it is related to that

matt.fellows
2022-03-03 12:22
That might be it. We moved the core from the CLI version of the verifier to the handle based on. It could be missed in that change

matt.fellows
2022-03-03 12:37
just realised you?re not on the latest. Can you please check out `10.0.0-beta.58` ?

matt.fellows
2022-03-03 12:37
Just ran it locally and can see setup/teardown running OK

toyamarinyon
2022-03-03 13:25
has joined #pact-js

david342
2022-03-03 13:26
has joined #pact-js

david342
2022-03-03 13:33
Hi could anyone help me with what seems like a simple question I want to match a value that can be 0 or 1 After much trying I arrive at trial: term({ matcher: "\\[0 - 1]", generate: 0 }), No luck - Example '0' does not match provided regular expression '\[0 - 1]' What am I doing wrong please ?

david342
2022-03-03 13:41
It looks like

david342
2022-03-03 13:42
trial: regex({ matcher: "[0 - 1]", generate: "0" }),

david342
2022-03-03 13:42
is what I need

timothyg
2022-03-03 16:02
I'll try the `--state-change-teardown` and if that doesn't work I'll see about bumping the version to the latest.

yesilmenadil
2022-03-03 16:14
has joined #pact-js

timothyg
2022-03-03 16:31
The `--state-change-teardown` arg didn't have any effect. But bumping to version to `10.0.0-beta.58` did work. The teardowns are now being executed.

mike.geeves064
2022-03-03 16:33
Glad to hear it's working, and also glad it wasn't broken as a result of my fix :grinning:

dajaman1
2022-03-03 20:30
has joined #pact-js

dajaman1
2022-03-03 20:36
Hi anyone can help me. I?m using pact in a debian container. When we use mocha as test framework everything works fine, our project uses jasmine as main test framework, when I switch to jasmine I got this error: `Unhandled promise rejection: Error: Pact startup failed; tried calling service 10 times with no result.` Nothing else is changed.

matt.fellows
2022-03-03 21:26
Are there any other logs?

matt.fellows
2022-03-03 21:26
You can?t apply regexes to numbers

matt.fellows
2022-03-03 21:26
they only work on strings

matt.fellows
2022-03-03 21:27
in this case, your only option is to do exact match on value (not ideal) or use the `like` matcher

dajaman1
2022-03-03 21:40
@matt.fellows these are the complete logs `NODE_ENV=test npx jasmine spec/contract/bsapi.spec.js` `Running tests with 'NODE_ENV=test'` `Started` `[2022-03-03 20:44:30.699 +0000] INFO (133 on 7d526b155d90): pact-node@10.17.1: Creating Pact Server with options:` `{"timeout":100000,"consumer":"ares-integration-services","cors":false,"dir":"/app/pacts","host":"0.0.0.0","log":"/app/logs/mockserver-integration.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"BSAPI","spec":2,"ssl":false,"port":1234,"pactFileWriteMode":"overwrite"}` `[2022-03-03 20:44:30.713 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: Starting pact binary '/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.81/pact/bin/pact-mock-service', with arguments [service --consumer ares-integration-services --cors false --pact_dir /app/pacts --host 0.0.0.0 --log /app/logs/mockserver-integration.log --log-level DEBUG --provider BSAPI --pact_specification_version 2 --ssl false --port 1234 --pact-file-write-mode overwrite]` `[2022-03-03 20:44:30.719 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: Created '/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.81/pact/bin/pact-mock-service' process with PID: 144` `[2022-03-03 20:44:36.922 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: INFO WEBrick 1.3.1` `INFO ruby 2.2.2 (2015-04-13) [x86_64-linux]` `[2022-03-03 20:44:36.922 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: INFO WEBrick::HTTPServer#start: pid=144 port=1234` `[2022-03-03 20:46:10.641 +0000] ERROR (133 on 7d526b155d90): pact@9.17.2: The pact mock service doesn't appear to be running` `- Please check the logs above to ensure that there are no pact service startup failures` `- Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method)` `- Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one` `- To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG'` `F[2022-03-03 20:46:10.649 +0000] ERROR (133 on 7d526b155d90): pact@9.17.2: The pact mock service doesn't appear to be running` `- Please check the logs above to ensure that there are no pact service startup failures` `- Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method)` `- Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one` `- To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG'` `Failures:` `1) BSAPI /bsapi/api/v1c/monitoring-series?baseline-id=ORD-2109329-02 when request is not authenticated should fail requiring authentication` `Message:` `Error: The pact mock service wasn't running when verify was called` `Stack:` `Error: The pact mock service wasn't running when verify was called` `at Pact.verify (/app/node_modules/@pact-foundation/pact/src/httpPact.js:108:35)` `at UserContext.<anonymous> (/app/spec/contract/bsapi.spec.js:59:28)` `at <Jasmine>` `Suite error: BSAPI` `Message:` `Unhandled promise rejection: Error: Pact startup failed; tried calling service 10 times with no result.` `Stack:` `Error: Pact startup failed; tried calling service 10 times with no result.` `at Server.retry (/app/node_modules/@pact-foundation/pact-node/src/service.js:177:33)` `at _rejected (/app/node_modules/q/q.js:864:24)` `at /app/node_modules/q/q.js:890:30` `at Promise.when (/app/node_modules/q/q.js:1142:31)` `at Promise.promise.promiseDispatch (/app/node_modules/q/q.js:808:41)` `at /app/node_modules/q/q.js:624:44` `at runSingle (/app/node_modules/q/q.js:137:13)` `at flush (/app/node_modules/q/q.js:125:13)` `at processTicksAndRejections (node:internal/process/task_queues:78:11)` `Message:` `Error: Timeout - Async function did not complete within 100000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)` `Stack:` `Error: Timeout - Async function did not complete within 100000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)` `at <Jasmine>` `at listOnTimeout (node:internal/timers:557:17)` `at processTimers (node:internal/timers:500:7)` `Message:` `Error: The pact mock service wasn't running when finalize was called` `Stack:` `Error: The pact mock service wasn't running when finalize was called` `at Pact.finalize (/app/node_modules/@pact-foundation/pact/src/httpPact.js:141:35)` `at UserContext.<anonymous> (/app/spec/contract/bsapi.spec.js:61:27)` `at <Jasmine>` `at processImmediate (node:internal/timers:464:21)` `1 spec, 2 failures` `Finished in 99.957 seconds`

matt.fellows
2022-03-03 21:42
can you please share your test setup? The error message has some helpful guides on what to do - are you sure `setup()` is called in the correct place etc.?

matt.fellows
2022-03-03 21:44
Awesome, thanks for confirming Timothy.

matt.fellows
2022-03-03 21:45
We?re back on track with the JS release now - so there will likely be a bunch of more beta updates before we cut over

matt.fellows
2022-03-03 21:45
The main thing left to do is plumb in message pact into the new core and then stabilise the public API

matt.fellows
2022-03-03 21:45
thanks for the feedback!

waqif
2022-03-03 23:32
has joined #pact-js

dmitry.matveev
2022-03-03 23:44
has joined #pact-js

tomas.sakinis
2022-03-04 06:38
has joined #pact-js

matt.fellows
2022-03-04 07:39
For those looking to level up their knowledge of contract testing @mcruzdrake is running a (paid) workshop at https://www.linkedin.com/company/thetesttribe/ on - ?Contract Testing with Pact JS ? Learn the basics of contract testing and implement it into your projects.?:test_tube: Use the promo code MARIEWQF for a nice little incentive:shushing_face: Learn more here :point_right: https://bit.ly/3tffW5a

david342
2022-03-04 09:19
Thanks didn't realise that . OK thats a pity

matt.fellows
2022-03-04 09:39
I'd suggest raising a matcher for a range of integer values here: https://github.com/pact-foundation/pact-specification/issues

david342
2022-03-04 10:43
Thanks I don't mind digging into the code and doing a PR , I'll see how to go about that

matt.fellows
2022-03-04 10:46
It?ll be rust code where that matcher will go, btw :wink:

david342
2022-03-04 10:50
Oh great I want to learn Rust where is the repo for all that


matt.fellows
2022-03-04 10:59
You should raise the suggestion first before issuing a PR, because it has ecosystem wide consequences and we would want to get a consensus that it?s a good idea

yousafn
2022-03-04 12:25
Would also be good to see your test setup files for Mocha and the equivalent for Jasmine. It looks like the pact mock service hasn't started, which may have been in a mocha specific setup file which you haven't got for jasmine. we have a mocha and jasmine example but as part of `karma` https://github.com/pact-foundation/pact-js/tree/master/examples/karma which uses pact-web which probably isn't what you are after

dajaman1
2022-03-04 12:59
@yousafn I don?t have any setup for mocha nor jasmine. I call both like this in the package.json: ?test:contract?: ?NODE_ENV=test jasmine spec/contract/*.spec.js? and for mocha ?test:contract?: ?NODE_ENV=test mocha --exit --recursive -R spec spec/contract/*.spec.js --timeout 10000"

yousafn
2022-03-04 13:04
Ahh thanks that is useful, so I assume your setup is in the test file(s) hook itself. what is the in the contents of the log file `app/logs/mockserver-integration.log` Also if you put three backticks before your code output in slack, you will get a nice formatted code block which is much easier to read :slightly_smiling_face: ````your code text`

dajaman1
2022-03-04 13:04
@matt.fellows I believe it is correctly setup, because the same code(just framework changes) is working in mocha That is the test setup `const path = require('path')` `const { Pact } = require('@pact-foundation/pact')` `describe('API', () => {` `let provider` `jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000` `provider = new Pact({` `consumer: 'ares-integration-services',` `provider: 'BSAPI',` `port: 1234,` `log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),` `dir: path.resolve(process.cwd(), 'pacts'),` `logLevel: 'DEBUG',` `timeout: 100000` `})` `beforeAll(async () => {` `await provider.setup()` `provider.addInteraction({` `state: 'the request is not authenticated',` `uponReceiving: 'a request for monitoring series',` `withRequest: {` `method: 'GET',` `path: '/api'` `},` `willRespondWith: {` `status: 401,` `headers: {` `'Content-Type': 'application/problem+json; charset=utf-8'` `}` `}` `})` `})` `describe('/api', () => {` `describe('when request is not authenticated', () => {` `it('should fail requiring authentication', async () => {` `expect(true).toBe(true)` `})` `})` `})` `afterEach(() => provider.verify())` `afterAll(() => provider.finalize())` `})`

yousafn
2022-03-04 13:06
I'll take a look and try and put some examples against a pact-js branch buddy

dajaman1
2022-03-04 13:12
In the log file there is nothing, when run with jasmine With mocha i got this, I know there is an error but the connection is working properly ```I, [2022-03-04T13:11:11.827524 #29] INFO -- : Registered expected interaction GET /api W, [2022-03-04T13:11:11.830281 #29] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api D, [2022-03-04T13:11:11.830585 #29] DEBUG -- : { "description": "a request for monitoring series", "providerState": "the request is not authenticated", "request": { "method": "GET", "path": "/api" }, "response": { "status": 401, "headers": { "Content-Type": "application/problem+json; charset=utf-8" } }, "metadata": null } W, [2022-03-04T13:11:11.831952 #29] WARN -- : Missing requests: GET /api I, [2022-03-04T13:11:11.845377 #29] INFO -- : Cleared interactions```

yousafn
2022-03-04 13:26
so to switch between `jasmine` and `mocha` I need to change the `beforeAll` / `afterAll` to `before`/`after` . In your script, you are using `expect` are you getting that from `chai` globally?

dajaman1
2022-03-04 13:27
you are right, and comment the jasmine.DEFAULT_?..

yousafn
2022-03-04 13:29
So this is a run in jasmine, with your code snippet above ```?? npm run test:jasmine ?? > mochajs-pact-example@1.0.0 test:jasmine > NODE_ENV=test rimraf pacts && jasmine test/*.jasmine.spec.js [2022-03-04 13:28:40.017 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Creating Pact Server with options: {"consumer":"ares-integration-services","cors":false,"dir":"/Users/saf/dev/pactoss/pact-js/examples/mocha/pacts","host":"127.0.0.1","log":"/Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":1234,"provider":"BSAPI","spec":2,"ssl":false} Randomized with seed 44043 Started [2022-03-04 13:28:40.025 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Starting pact binary 'standalone/darwin-1.88.63/pact/bin/pact-mock-service', with arguments [service --consumer ares-integration-services --pact_dir /Users/saf/dev/pactoss/pact-js/examples/mocha/pacts --host 127.0.0.1 --log /Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log --pact-file-write-mode overwrite --port 1234 --provider BSAPI --pact_specification_version 2] [2022-03-04 13:28:40.029 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Created 'standalone/darwin-1.88.63/pact/bin/pact-mock-service' process with PID: 59113 [2022-03-04 13:28:40.428 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2022-03-04 13:28:40.428 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO WEBrick::HTTPServer#start: pid=59113 port=1234 [2022-03-04 13:28:40.550 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact@9.16.0: Setting up Pact with Consumer "ares-integration-services" and Provider "BSAPI" using mock service on Port: "1234" Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /api See /Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log for details. F[2022-03-04 13:28:40.570 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact@9.16.0: Pact File Written [2022-03-04 13:28:40.570 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Removing Pact process with PID: 59113 [2022-03-04 13:28:40.571 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Deleting Pact Server with options: {"consumer":"ares-integration-services","cors":false,"dir":"/Users/saf/dev/pactoss/pact-js/examples/mocha/pacts","host":"127.0.0.1","log":"/Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":1234,"provider":"BSAPI","spec":2,"ssl":false} [2022-03-04 13:28:40.572 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. Failures: 1) API /api when request is not authenticated should fail requiring authentication Message: Error: Pact verification failed - expected interactions did not match actual. Stack: at new VerificationError (/Users/saf/dev/pactoss/pact-js/examples/mocha/node_modules/@pact-foundation/pact/src/errors/verificationError.js:19:42) at /Users/saf/dev/pactoss/pact-js/examples/mocha/node_modules/@pact-foundation/pact/src/httpPact.js:108:23 at processTicksAndRejections (node:internal/process/task_queues:96:5) 1 spec, 1 failure Finished in 0.554 seconds Randomized with seed 44043 (jasmine --random=true --seed=44043)```

yousafn
2022-03-04 13:30
This is my command to start `"test:jasmine": "rimraf pacts && jasmine test/*.jasmine.spec.js"` so it looks like the mock provider started ok here. You mentioned this was also running inside a docker container?

dajaman1
2022-03-04 13:32
Yes, I?m using a debian stretch image as a container

yousafn
2022-03-04 13:32
I'll try the same versions of pact as you and then can stick this in a container and see what happens. `pact-node@10.17.1` `pact@9.17.2`

yousafn
2022-03-04 13:33
got a dockerfile handy?

dajaman1
2022-03-04 13:36
I have it, but it has some sensitive information in it(it would take some time to clear), I?m kinda afraid to share it, sorry

yousafn
2022-03-04 13:39
No that is absolutely fine my friend, appreciate that, I can setup a debian image easily enough :slightly_smiling_face: I have an example here in fork https://github.com/YOU54F/pact-js/commit/404e83ab4dadbf505711055410aba80a683b1b80 under the https://github.com/YOU54F/pact-js/compare/jasmineExamples branch. If you go to `examples/mocha` and run `npm i` and then `npm test:jasmine` that is working for me. The mocha version is complaining that `expect(...).toBe is not a function` you can run that with `npm:test`

yousafn
2022-03-04 13:45
There is a docker example file in pact-js so I will switch that out for debian and see how we go :slightly_smiling_face: https://github.com/pact-foundation/pact-js/tree/feat/docker-example/docker

reuben.tonna
2022-03-04 14:32
has joined #pact-js

dajaman1
2022-03-04 14:46
@yousafn I was able to solve the issue, there was a ?hidden? nock configuration that was blocking any connection :upside_down_face:, I really appreciate your help, thank you so much.

yousafn
2022-03-04 14:54
Oh fantastic dude! And no problem

negrolyze
2022-03-04 15:34
has joined #pact-js

alanbos
2022-03-04 17:49
Hi - does anyone have a simple example of using `GraphQLInteraction` with PactV3? I'm struggling with how to use it in the following approach as I'm not sure PactV3 has an `addInteraction()` method: ```const provider = new PactV3(...); describe('query', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a query') .withQuery('...') .withVariables({}) .withRequest({ path: '/graphql', method: 'POST', }) .willRespondWith({ status: 200, headers: { ... }, body: { ... } }); return provider.addInteraction(graphqlQuery); <-- IS THIS VALID? )}; )}; ```

42amehmeto
2022-03-04 19:17
has joined #pact-js

rawatankit90
2022-03-04 22:33
has joined #pact-js

matt.fellows
2022-03-04 23:35
V3 doesn't have a graphql API at the moment

alanbos
2022-03-05 00:03
Thanks Matt

matt.fellows
2022-03-05 01:05
If you take a look at the current graphql interface you could see how it's done. It's a very simple facade

matt.fellows
2022-03-05 01:05
Or a PR into the v3.x.x branch would be great too

alanbos
2022-03-05 07:01
I'll take a look - thanks again.

alanbos
2022-03-05 09:39
@matt.fellows for the PactV3 class, would the correct approach here be to subclass that class with the additional Graphql dsl methods (e.g. withVariables()) - just want to make sure I understand the intention behind the new design.

matt.fellows
2022-03-06 10:52
I think for now that?s probably the best idea

artur
2022-03-07 04:04
I'm back to trying to update 10.0.0-beta.36 to 10.0.0-beta.58 found that I need to set `contentType:` now if the requests are not json but now I'm getting `PactffiGivenWithParam(arg 2) expected a string` I cannot see what can be wrong in that `uponReceiving` request ``` 183 | }) 184 | return provider > 185 | .uponReceiving(`as ${sharer}, a GET request to get single share of '${resource}' ${requestName}`) | ^ 186 | .withRequest({ 187 | method: 'GET', 188 | path: fromProviderState( at givenWithParam (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:139:22) at Object.givenWithParam (node_modules/@pact-foundation/pact-core/src/consumer/checkErrors.ts:9:21) at node_modules/@pact-foundation/src/v3/pact.ts:238:28 at forEachObjIndexed (node_modules/ramda/src/forEachObjIndexed.js:34:5) at f2 (node_modules/ramda/src/internal/_curry2.js:29:14) at node_modules/@pact-foundation/src/v3/pact.ts:237:26 at Array.forEach (<anonymous>) at PactV3.uponReceiving (node_modules/@pact-foundation/src/v3/pact.ts:235:17) at getShareInteraction (tests/sharingTest.js:185:8) at Object.<anonymous> (tests/sharingTest.js:701:11)```

matt.fellows
2022-03-07 04:11
I've just popped out Artur but will look when back. This has the new core in it so could be a few teething issues/arts mapped incorrectly

matt.fellows
2022-03-07 04:12
I've got a plan to not make contentType mandatory soon. I'd like to introduce a new builder API but leave the existing one for compatibility. The reason is there are a lot more options/code paths and it's not obvious by looking at the API. I'd like to make that clearer and to prevent state issues by a proper builder API


matt.fellows
2022-03-07 04:22
But should be calling the other branch

matt.fellows
2022-03-07 04:22
I'm guessing there is a logic flaw in that code

matt.fellows
2022-03-07 04:35
Oh, what does you given look like?

artur
2022-03-07 05:02
```provider.given('the user is recreated', { username: user, password: password })```

artur
2022-03-07 05:02
I see that given only accepts a string now `given(providerState: string): this;`


artur
2022-03-07 05:41
we are using multiple functions to create the provider object, maybe this is the issue `// TODO: this currently must be called before other methods, else it won't work`

matt.fellows
2022-03-07 05:56
ah, maybe!

matt.fellows
2022-03-07 05:59
> I see that given only accepts a string now `given(providerState: string): this;` Where are you seeing this?

artur
2022-03-07 06:31
my IDE takes me to node_modules/@pact-foundation/pact/src/dsl/interaction.d.ts but that is wrong, because I need to look into the V3 code

artur
2022-03-07 06:43
getting rid of all givens makes it pass

matt.fellows
2022-03-07 06:44
Thanks Artur.

matt.fellows
2022-03-07 06:44
What does your current `given` look like?

matt.fellows
2022-03-07 06:45
This, by the way, is exactly the kind of state related problem I?d like to solve with a type-state builder API

artur
2022-03-07 06:51
the issue is `optionalParams` in this part ```provider .given('resource is shared', { username, userPassword, path, shareType: SHARE_TYPE.group, shareWith, ...optionalParams }``` where optionalParams = {permissions: undefined, expireDate: undefined, attributes: undefined}

artur
2022-03-07 06:53
the issue are the undefined values ` ```given('resource is shared', { x: 'some value' })``` works but ` ```.given('resource is shared', { x: undefined })``` crashes

artur
2022-03-07 06:54
bug or feature?

matt.fellows
2022-03-07 06:54
bug, I think

matt.fellows
2022-03-07 06:55
You want `undefined` to come through, I?m assuming? No reason I can think of that we shouldn?t allow that to happen

matt.fellows
2022-03-07 06:57
I think it?s because we `JSON.stringify(value)` but `undefined` doesn?t stringify

artur
2022-03-07 07:01
cannot reproduce in examples

artur
2022-03-07 07:02
old version of pact-js, trying again

matt.fellows
2022-03-07 07:05
Ah. So `undefined` is not actually valid JSON. It can be passed around in JS, but it?s not JSON itself. This could be the cause of the interop issue here

matt.fellows
2022-03-07 07:05
can you use `null`?

matt.fellows
2022-03-07 07:05
(or omit the property altogether?)


matt.fellows
2022-03-07 07:09
I think I should update the Typescript type to prevent the use of undefined in the parameters - that?s the first step

matt.fellows
2022-03-07 07:09
but it won?t fix JS users, so it will need some validation also

matt.fellows
2022-03-07 07:10
I think we should explictly error if we find `undefined` because it may lead to unintended consequences

matt.fellows
2022-03-07 07:11
In your case, I?m not sure what works best - replacing `undefined` with `null` or some alternative?

artur
2022-03-07 07:12
I'm trying now ``` optionalParams = JSON.stringify(optionalParams) optionalParams = JSON.parse(optionalParams)```

artur
2022-03-07 07:12
that should delete all keys with undefined values


matt.fellows
2022-03-07 07:41
Excellent! Thanks for letting me know. I'll fix the above in the next release (next few days)

tom.daley
2022-03-07 09:09
has joined #pact-js

leon.brown
2022-03-07 09:26
has joined #pact-js

matt.fellows
2022-03-07 10:14
I?ve made a patch locally for this. It?s not my ideal solution, but having it will prevent a regression and provide a target for addressing later.

matt.fellows
2022-03-07 10:14
I?ll push it up in the next couple of days

aurelia.rochat
2022-03-07 10:16
has joined #pact-js

kabhatiya
2022-03-08 00:51
has joined #pact-js

luis.garelli
2022-03-08 09:29
has joined #pact-js

andrevdrodrigues
2022-03-08 12:50
has joined #pact-js

tobias
2022-03-08 13:11
has joined #pact-js

mutharaju.kk
2022-03-08 14:34
has joined #pact-js

gerry
2022-03-08 14:48
@gerry has left the channel

will.robinson
2022-03-08 14:54
has joined #pact-js

nathan.deamer
2022-03-08 15:00
has joined #pact-js

fragonib
2022-03-08 16:22
has joined #pact-js

jason.wang
2022-03-08 19:05
has joined #pact-js

sam680
2022-03-09 05:12
has joined #pact-js

artur
2022-03-09 05:37
my matching rules for response end up in the request in the JSON ```provider .given('the user is recreated', { username: user, password: password }) .uponReceiving(`as '${user}', a GET to get current user information`) .withRequest({ method: 'GET', path: MatchersV3.regex( /.*\/ocs\/v1\.php\/cloud\/user$/, '/ocs/v1.php/cloud/user' ), headers: { authorization: getAuthHeaders(user, password) } }) .willRespondWith({ status: 200, headers: applicationXmlContentType, body: new XmlBuilder('1.0', '', 'ocs').build(ocs => { ocs.appendElement('meta', '', (meta) => { meta.appendElement('status', '', MatchersV3.equal('ok')) .appendElement('statuscode', '', MatchersV3.equal('100')) .appendElement('message', '', MatchersV3.equal('OK')) }).appendElement('data', '', (data) => { data.appendElement('id', '', MatchersV3.equal(user)) data.appendElement('display-name', '', MatchersV3.regex(`(${user}|${displayName})`, user)) data.appendElement('email', '', MatchersV3.regex(`(${user}@example\\..*)?`, '')) }) }) })``` gives me: ``` "request": { "headers": { "authorization": "Basic dGVzdDEyMzp0ZXN0MTIz" }, "matchingRules": { "body": { "$.ocs.data.display-name.#text": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "(test123|Test123)" } ] }, "$.ocs.data.email.#text": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "(test123@example\\..*)?" } ] }, "$.ocs.data.id.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] }, "$.ocs.meta.message.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] }, "$.ocs.meta.status.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] }, "$.ocs.meta.statuscode.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] } }, "header": {}, "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": ".*\\/ocs\\/v1\\.php\\/cloud\\/user$" } ] } }, "method": "GET", "path": "/ocs/v1.php/cloud/user" }, "response": { "body": "<?xml version='1.0'?><ocs><meta><status>ok</status><statuscode>100</statuscode><message>OK</message></meta><data><id>test123</id><display-name>test123</display-name><email></email></data></ocs>", "headers": { "Content-Type": "application/xml; charset=utf-8" }, "status": 200 }``` all the matches are there but in the wrong place

matt.fellows
2022-03-09 05:49
:scream:

matt.fellows
2022-03-09 05:49
let me take a look. Only happening with XML ones?

artur
2022-03-09 05:52
trying to confirm

artur
2022-03-09 05:54
at least in my tests JSON works fine

matt.fellows
2022-03-09 06:02
(checking now locally)

matt.fellows
2022-03-09 06:03
Yes, I also get this. I?ll find the source of the problem now

matt.fellows
2022-03-09 06:07
found it, I?ll submit a PR now


artur
2022-03-09 06:13
thx for the quick fix

matt.fellows
2022-03-09 06:14
Np. Might take a little bit to release and propagate into the libs, but will tap Ron on the shoulder tomorrow at standup.

annette.reid
2022-03-09 07:43
has joined #pact-js


sebastianman45
2022-03-09 15:51
has joined #pact-js

victor.lau
2022-03-09 20:46
has joined #pact-js

qluck
2022-03-09 21:41
Hi all! I'm trying to find a good way to debug my tests in Intellij. Does anyone have a run configuration or any general tips of how to set this up? I haven't been able to hit a single breakpoint in any of my tests. Thanks in advance!

uglyog
2022-03-09 22:18
Might be easier to use Visual Studio Code. It is very easy to setup debugging with that.

qluck
2022-03-09 22:47
ok, thanks

kenneth.krause
2022-03-10 16:41
has joined #pact-js

caiquedpfc
2022-03-10 19:14
Hello everyone, how are you? I have generated a contract using pact-js in my consumer for a GraphQL API, but I?m getting an error when I try to verify this contract with pact-very or with pact-python in my provider, I believe this is an error with my contract the error I?m getting when I try to verify this contract is `GraphQL operations must contain a non-empty query or a persistedQuery` anyone knows how to solve this? I?m sharing my contract bellow and the code I?m using to generate the contract

caiquedpfc
2022-03-10 19:14
follow my contract bellow: ```{ "consumer": { "name": "courier-phoenix" }, "provider": { "name": "courier-api" }, "interactions": [ { "description": "A request with a new show case", "request": { "method": "POST", "path": "/public-api", "headers": { "content-type": "application/json" }, "body": { "operationName": "loadNewShowCase", "query": "query loadNewShowCase($filter: ShowCaseFilter) {\n loadNewShowCase(filter: $filter) {\n messages {\n category\n target\n key\n message\n }\n showCase {\n images\n shelves {\n id\n type\n displayName\n hasNextItems\n items {\n id\n type\n images\n displayName\n applicableDiscount {\n presentedDiscountValue\n discountType\n finalValue\n }\n category {\n id\n displayName\n }\n brand {\n id\n displayName\n }\n price {\n min\n max\n }\n }\n }\n }\n }\n}\n", "variables": { } }, "matchingRules": { "$.body.query": { "match": "regex", "regex": "query\\s*loadNewShowCase\\(\\$filter:\\s*ShowCaseFilter\\)\\s*\\{\\s*loadNewShowCase\\(filter:\\s*\\$filter\\)\\s*\\{\\s*messages\\s*\\{\\s*category\\s*target\\s*key\\s*message\\s*\\}\\s*showCase\\s*\\{\\s*images\\s*shelves\\s*\\{\\s*id\\s*type\\s*displayName\\s*hasNextItems\\s*items\\s*\\{\\s*id\\s*type\\s*images\\s*displayName\\s*applicableDiscount\\s*\\{\\s*presentedDiscountValue\\s*discountType\\s*finalValue\\s*\\}\\s*category\\s*\\{\\s*id\\s*displayName\\s*\\}\\s*brand\\s*\\{\\s*id\\s*displayName\\s*\\}\\s*price\\s*\\{\\s*min\\s*max\\s*\\}\\s*\\}\\s*\\}\\s*\\}\\s*\\}\\s*\\}\\s*" } } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "data": { "loadNewShowCase": { "messages": null, "showCase": { "images": [ ], "shelves": [ { "id": "31239bf8-e8d8-4893-a3de-7e5316a8e6fd", "type": "BILLBOARD", "displayName": "Destaques", "hasNextItems": false, "items": [ { "id": "b7566f41-db87-4b03-bef2-4531a5b6de50", "type": "BANNER", "images": [ "https://courier-images-frontrelease.imgix.net/banner/b7566f41-db87-4b03-bef2-4531a5b6de50_180cab5b-ae61-4b28-9b6e-2124815cf974.jpg" ], "displayName": "TESTEQA10", "applicableDiscount": null, "category": null, "brand": null, "price": null } ] } ] } } }, "default": { "data": { "loadNewShowCase": { "messages": null, "showCase": { "images": [ ], "shelves": [ { "id": "31239bf8-e8d8-4893-a3de-7e5316a8e6fd", "type": "BILLBOARD", "displayName": "Destaques", "hasNextItems": false, "items": [ { "id": "b7566f41-db87-4b03-bef2-4531a5b6de50", "type": "BANNER", "images": [ "https://courier-images-frontrelease.imgix.net/banner/b7566f41-db87-4b03-bef2-4531a5b6de50_180cab5b-ae61-4b28-9b6e-2124815cf974.jpg" ], "displayName": "TESTEQA10", "applicableDiscount": null, "category": null, "brand": null, "price": null } ] } ] } } } } }, "matchingRules": { "$.body": { "match": "type" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

caiquedpfc
2022-03-10 19:17
And the code to generate the contract is: ```import { ApolloGraphQLInteraction, Matchers, Pact } from '@pact-foundation/pact' import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client' import * as loadNewShowCaseExpectedResponse from './mocks/loadNewShowCase.json'; import { showCase } from '../../../src/services/api/showcase'; import { print } from 'graphql' import fetch from 'cross-fetch' import path from 'path'; jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000; const PORT = 20002; describe("Show Case", () => { const provider = new Pact({ port: PORT, log: path.resolve(process.cwd(), "aut-tests/contract/logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "aut-tests/contract/pacts"), spec: 2, logLevel: 'DEBUG', pactfileWriteMode: "overwrite", consumer: "courier-phoenix", provider: "courier-api", }) beforeAll(() => provider.setup()); afterAll(() => provider.finalize()); describe("Load New Show Case", () => { beforeEach(() => { const graphqlQueryInteraction = new ApolloGraphQLInteraction() .uponReceiving("A request with a new show case") .withRequest({ path: "/public-api", method: "POST", }) .withOperation("loadNewShowCase") .withQuery(print(gql`query loadNewShowCase($filter: ShowCaseFilter) {${showCase}}`)) .withVariables({}) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: Matchers.like(loadNewShowCaseExpectedResponse) }); return provider.addInteraction(graphqlQueryInteraction) }) test("returns correct body, header and statusCode", async() => { const client = new ApolloClient({ cache: new InMemoryCache({ addTypename: false }), link: new HttpLink({ uri: `${provider.mockService.baseUrl}/public-api`, fetch }), }) let response = client .query({ query: gql`query loadNewShowCase($filter: ShowCaseFilter) { ${showCase} }` }) response = await response.then((result: any) => { result.data expect(result.data).toEqual(loadNewShowCaseExpectedResponse) }) .catch( error => { return error }) }) afterEach(() => provider.verify()) }) })```

bergner
2022-03-11 06:19
has joined #pact-js

harwin1494
2022-03-11 06:24
Hello all! I am working on writing test for 'register user' scenario, whose request takes parameters as firstname, lastname, emailaddress. I created a consumer test with specific request parameter values for example: firstname - 'Testfirstname' lastname - 'Testlastname' emailaddress - '' In the interaction file that was generated, the above values get hardcoded. Hence while running the test at Provider side, the test passes for first time but fails later , because the user with same emailaddress cannot be created due to conflict. Is there any way to avoid hardcoding of user details in pact file or make these values unique each time it is run at Provider end?

matt.fellows
2022-03-11 06:25
Are you running your tests against a live provider?

harwin1494
2022-03-11 06:25
eventually they would be

matt.fellows
2022-03-11 06:25
oh, don?t do that. That?s not ideal

matt.fellows
2022-03-11 06:26
You want to be able to run the provider tests against a locally spun up version of the provider that can control its own data

harwin1494
2022-03-11 06:26
like a virtualization server?

matt.fellows
2022-03-11 06:26
no, like in a dev environment

matt.fellows
2022-03-11 06:26
e.g. `npm start` with dependencies mocked

matt.fellows
2022-03-11 06:27
1. Start dev server 2. Run pact tests 3. shutdown dev server 4. [if on CI] publish verification results 5. [if on CI] run can-i-deploy 6. [if on CI and 5 passes] deploy

matt.fellows
2022-03-11 06:27
general workflow for a pact project

harwin1494
2022-03-11 06:27
okay, but is there any way to achieve the uniqueness in case of email-ids getting generated everytime we run the consumer?

harwin1494
2022-03-11 06:28
any randomized function or something like that?

matt.fellows
2022-03-11 06:53
Why is it a problem though? If you run it in a unit-test like context, the data is clean so there shouldn?t be conflicts

matt.fellows
2022-03-11 06:53
also, there are hooks (see the docs) that can fire pre/post test you can use to clear out any state in the database (if necessary) to achieve the same thing

matt.fellows
2022-03-11 06:54
If I said you needed to randomise an email address in your unit test email validation procedure because the email address already existed, you would likely tell me that something is wrong with my unit test. That?s essentially the mindset to bring to this problem

gotax80534
2022-03-11 06:55
has joined #pact-js

mathias
2022-03-11 10:17
has joined #pact-js

harwin1494
2022-03-11 10:57
This sounds right, thanks for clarifying Matt.

jtcsek
2022-03-11 13:02
has joined #pact-js

alanbos
2022-03-12 15:24
Hi I'm running the latest Pactv3 beta pact-js consumer and the mocked server is returning null for a response body property based on `arrayContaining` - there are other properties using that matcher which are working fine. Is this a known issue, or is there something in the logs I should be looking for to give me a clue?

matt.fellows
2022-03-12 21:22
If you could please set log level to debug and share we could take a look

alanbos
2022-03-12 23:08
Thanks Matt I'll simplify the pact as much as possible and post the debug on Monday. Incidentally hit an issue with the date(pattern, value) matcher in Pactv3 js beta where the mock server always returns todays date rather the value I specify as the 2nd arg.

matt.fellows
2022-03-13 02:27
Thanks. I'll take a look at the date matcher next time I'm in there

joachim005
2022-03-14 08:16
has joined #pact-js

alexstout009
2022-03-14 14:32
has joined #pact-js

paul.richards
2022-03-14 14:38
has joined #pact-js

akif.tahir
2022-03-14 15:00
has joined #pact-js

lramos
2022-03-14 16:29
has joined #pact-js

michael036
2022-03-14 18:31
has joined #pact-js

lauren.coggin
2022-03-14 19:27
has joined #pact-js

mkanika1811
2022-03-15 09:22
has joined #pact-js

ian.pringle
2022-03-15 11:02
has joined #pact-js

karl.wagner
2022-03-15 12:25
has joined #pact-js

chaitasi.patel988
2022-03-16 04:04
has joined #pact-js

mathias
2022-03-16 08:05
@mathias has left the channel

jose.iglesias
2022-03-16 09:23
has joined #pact-js

alanbos
2022-03-16 10:12
Hi Matt - having narrowed things down a bit I think the issue might be due to nested arrayContaining. This is the query: ```query badQuery($id: ID!) { foo(id: $id) { bar { results { __typename } } } }``` This is the expectation: ```foo: { bar: arrayContaining( { results: arrayContaining({ __typename: equal('Result') }) } ) }``` This is the debug level log: ```[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.variables [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.variables.id [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.__typename [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results[*] [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results[*].__typename [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Skipping the matching rule (skip_matchers == true) [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar[*] [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar[*].results [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Skipping the matching rule (skip_matchers == true) [2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries: core/interaction/http core/interaction/https [2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries: core/content-generator/binary core/content-generator/json core/content-matcher/json core/content-matcher/multipart-form-data core/content-matcher/text core/content-matcher/xml [2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries: core/matcher/v1-equality core/matcher/v2-max-type core/matcher/v2-min-type core/matcher/v2-minmax-type core/matcher/v2-regex core/matcher/v2-type core/matcher/v3-content-type core/matcher/v3-date core/matcher/v3-datetime core/matcher/v3-decimal-type core/matcher/v3-includes core/matcher/v3-integer-type core/matcher/v3-null core/matcher/v3-number-type core/matcher/v3-time core/matcher/v4-array-contains core/matcher/v4-equals-ignore-order core/matcher/v4-max-equals-ignore-order core/matcher/v4-min-equals-ignore-order core/matcher/v4-minmax-equals-ignore-order core/matcher/v4-not-empty core/matcher/v4-semver [2022-03-16T10:07:04Z DEBUG pact_mock_server::mock_server] Started mock server on 127.0.0.1:65384 [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::io] parsed 7 headers [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::conn] incoming body is content-length (178 bytes) [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::conn] incoming body completed [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Creating pact request from hyper request [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Extracting query from uri /graphql [2022-03-16T10:07:04Z INFO pact_mock_server::hyper_server] Received request HTTP Request ( method: POST, path: /graphql, query: None, headers: Some({"host": ["127.0.0.1:65384"], "content-type": ["application/json"], "content-length": ["178"], "user-agent": ["node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"], "accept": ["*/*"], "connection": ["close"], "accept-encoding": ["gzip", "deflate"]}), body: Present(178 bytes, application/json) ) [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] body: '{"operationName":"badQuery","variables":{"id":"1"},"query":"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"}' [2022-03-16T10:07:04Z INFO pact_matching] comparing to expected HTTP Request ( method: POST, path: /graphql, query: None, headers: Some({"Content-Type": ["application/json"]}), body: Present(178 bytes, application/json) ) [2022-03-16T10:07:04Z DEBUG pact_matching] body: '{"operationName":"badQuery","query":"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}","variables":{"id":"1"}}' [2022-03-16T10:07:04Z DEBUG pact_matching] matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("variables"), Field("id")], expr: "$.variables.id" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }, PATH: MatchingRuleCategory { name: PATH, rules: {} }} } [2022-03-16T10:07:04Z DEBUG pact_matching] generators: Generators { categories: {} } [2022-03-16T10:07:04Z DEBUG pact_matching::matchers] String -> String: comparing '/graphql' to '/graphql' using Equality (false) [2022-03-16T10:07:04Z DEBUG pact_matching] expected content type = 'application/json', actual content type = 'application/json' [2022-03-16T10:07:04Z DEBUG pact_matching] content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }' [2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Looking for a content matcher for application/json [2022-03-16T10:07:04Z DEBUG pact_matching] No content matcher defined for content type 'application/json', using core matcher implementation [2022-03-16T10:07:04Z DEBUG pact_matching] Using body matcher for content type 'application/json' [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $ [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_maps: Comparing maps at $: {"operationName": String("badQuery"), "query": String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"), "variables": Object({"id": String("1")})} -> {"operationName": String("badQuery"), "query": String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"), "variables": Object({"id": String("1")})} [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.operationName [2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"badQuery"' to '"badQuery"' using Equality -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("badQuery")' to 'String("badQuery")' at path '$.operationName' -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.query [2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"' to '"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"' using Equality -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}")' to 'String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}")' at path '$.query' -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.variables [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_maps: Comparing maps at $.variables: {"id": String("1")} -> {"id": String("1")} [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.variables.id [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Calling match_values for path $.variables.id [2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"1"' to '"1"' using Type -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("1")' to 'String("1")' at path '$.variables.id' -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching] --> Mismatches: [] [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Test context = {"mockServer": Object({"href": String("http://127.0.0.1:65384"), "port": Number(65384)})} [2022-03-16T10:07:04Z INFO pact_mock_server::hyper_server] Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(43 bytes, application/json) ) [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] body: '{"data":{"foo":{"bar":[{"results":null}]}}}' [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::io] flushed 355 bytes [2022-03-16T10:07:04Z INFO pact_mock_server::mock_server] Writing pact out to 'C:\Dev\git_repos\apps\case_notes_on_the_go\pacts\ena-app-apigateway.json' [2022-03-16T10:07:04Z DEBUG pact_models::pact] Merging pact with file "C:\\Dev\\git_repos\\apps\\case_notes_on_the_go\\pacts\\ena-app-apigateway.json" [2022-03-16T10:07:04Z WARN pact_models::pact] Note: Existing pact is an older specification version (V3), and will be upgraded [2022-03-16T10:07:04Z DEBUG pact_mock_server::server_manager] Shutting down mock server with port 65384 [2022-03-16T10:07:04Z DEBUG pact_mock_server::server_manager] Shutting down mock server with port 65384 - MockServerMetrics { requests: 1 } [2022-03-16T10:07:04Z DEBUG pact_mock_server::mock_server] Mock server cf98a3b4-4aa0-4836-8bcb-9f144d34a04b shutdown - MockServerMetrics { requests: 1 } [2022-03-16T10:07:04Z DEBUG hyper::server::shutdown] signal received, starting graceful shutdown Error: expect(received).resolves.toEqual(expected) // deep equality - Expected - 5 + Received + 1 Object { "foo": Object { "bar": Array [ Object { - "results": Array [ - Object { - "__typename": "Result", - }, - ], + "results": null, }, ], }, }```

alegab0710
2022-03-16 10:20
has joined #pact-js

matt.fellows
2022-03-16 10:24
Thanks. It looks to be returning `{"data":{"foo":{"bar":[{"results":null}]}}}` despite the nested `arrayContaining`

matt.fellows
2022-03-16 10:25
Could you please raise the bug at https://github.com/pact-foundation/pact-js/issues/ and we?ll get it looked into? I can?t tell from here if the issue is in Pact JS or the (rust) core.

matt.fellows
2022-03-16 10:25
Suspect core, at this stage

alanbos
2022-03-16 10:48
OK thanks - will do


matt.fellows
2022-03-16 11:16
Awesome, thanks

serghei.pogodin
2022-03-16 12:31
has joined #pact-js

jeremy.vincent
2022-03-16 14:29
has joined #pact-js

1.g10squad
2022-03-16 16:01
has joined #pact-js

alistair.c.kung
2022-03-16 18:44
has joined #pact-js

adam.howard
2022-03-17 02:05
has joined #pact-js

jonatan.jaworski
2022-03-17 02:32
has joined #pact-js

lewis.greenway-jones
2022-03-17 08:52
has joined #pact-js

pierre.gerard
2022-03-17 11:59
has joined #pact-js

viswanathan.sarma
2022-03-17 22:39
has joined #pact-js

madhulika.mitra
2022-03-18 15:56
has joined #pact-js

yesilmenadil
2022-03-20 15:25
set the channel topic: Questions and updates about Pact in JS/TS/node. See also #pact-js-development for contribution or development questions. All questions welcome!

peter.pinda
2022-03-21 02:56
Hey guys, I am getting these response from API: This response going to be always like this (much more items). Notice certain slug wont have subfields(null)... looking into the matchers knowing Pact is not supporting optional fields.... is there any recommended way I can follow ? Thanks ```[ { "slug": "with-fields", "subFields":[ { "name":"name", "required":true } ] }, { "slug":"without-fields", "subFields":null } ]``` PS: I know based on slug which item has fields and which doesn't

matt.fellows
2022-03-21 05:43
You need to write two separate tests: one with the optional fields set and another without

matt.fellows
2022-03-21 05:43
You could also consider the use of the `arrayContaining` matcher in the v3 beta release

peter.pinda
2022-03-21 06:44
Thanks @matt.fellows

rupam.saha
2022-03-21 09:26
has joined #pact-js

christian.jeppesen
2022-03-21 10:10
has joined #pact-js

anand.kannan
2022-03-21 10:10
has joined #pact-js

mikhail.yartsev
2022-03-21 10:10
has joined #pact-js

mircea.ungureanu
2022-03-21 13:29
Good afternoon, I?m getting this error and not sure how to get past it `: Timeout - Async callback was not invoked within the 15000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 15000 ms timeout specified by jest.setTimeout.Error:` I tried increasing the jest timeout but no luck, it?s failing on the `return await p.verify();` as it?s an open handle and keeping jest from exiting. Has anyone encountered this before? I?ve sent my access token and url env vars.

mircea.ungureanu
2022-03-21 14:53
This is now resolved, it was a timeout problem.

bblechman
2022-03-21 16:36
has joined #pact-js

jeffrey2011998
2022-03-22 09:22
has joined #pact-js

xavier.arque
2022-03-22 11:33
has joined #pact-js

bernard
2022-03-22 13:40
Hi I'm running my Pact tests inside a docker container. And I'm having trouble running a basic Pact test. ```test(`makes a request`, async () => { jest.setTimeout(30000); // Arrange const expectedResult = `Hello World`; await mockProvider.addInteraction({ state: `foo exists`, uponReceiving: `a request to get foo`, withRequest: { method: `GET`, path: `/foo` }, willRespondWith: { status: 200, headers: { "Content-Type": regex({ generate: `text/plain`, matcher: `text/plain;?.*` }) }, body: like(expectedResult) } }); const request = await http://axios.post( `${mockProvider.mockService.baseUrl}/foo` ); console.log(request); });``` My Pact logs are: ```I, [2022-03-22T13:37:53.003897 #348] INFO -- : Registered expected interaction GET /foo W, [2022-03-22T13:38:22.980712 #348] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /foo W, [2022-03-22T13:38:22.980965 #348] WARN -- : Missing requests: GET /foo I, [2022-03-22T13:38:23.015926 #348] INFO -- : Cleared interactions``` Any ideas?? Do I need to expose a port on my container???

yousafn
2022-03-22 14:21
You are making a post request to your mock server but have registered an expectation of a GET request. You should be testing your client in your application which inside it, would call out to the providing service. You would traditionally set up your api interface so that you can pass in the provider service base url, and with pact you would pass in the mock providers base url to the api client. Hope that makes sense!

aubrey
2022-03-22 14:32
has joined #pact-js

balazs
2022-03-22 15:51
has joined #pact-js

agustin.gomes
2022-03-22 17:23
Hello everyone, I'm trying to setup a small Typescript project to use Pact, The test is setup as follows: ? a Docker container with the app and the test ? a separate Docker container where the mock server is running It seems that PactJS assumes I want to setup the mock server in the same place as the app, which is not possible since Ruby is not installed. Is there a way around it? If I do cURL from the app container, I get this: ```docker-compose run --rm node-cli curl -X GET pact-mock-provider:1234 Creating rover_node-cli_run ... done {"message":"No interaction found for GET /","interaction_diffs":[]} ``` But if I run the tests, I get the following: ```docker-compose run --rm node-cli npm run test:mocha:consumer Creating rover_node-cli_run ... done > test:mocha:consumer > mocha src/consumer.spec.ts [2022-03-22 17:21:28.234 +0000] INFO (18 on node-cli): pact-node@10.17.2: Creating Pact Server with options: {"timeout":30000,"consumer":"testingConsumer","cors":false,"dir":"/opt/project/roverctl/pacts","host":"pact-mock-provider","log":"/opt/project/roverctl/stderr","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"testingProvider","spec":2,"ssl":false,"port":1234,"pactFileWriteMode":"overwrite"} (node:18) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) GraphQL example 1) "before all" hook in "GraphQL example" [2022-03-22 17:21:28.248 +0000] ERROR (18 on node-cli): pact@9.17.3: The pact mock service doesn't appear to be running - Please check the logs above to ensure that there are no pact service startup failures - Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method) - Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one - To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG' 2) "after all" hook in "GraphQL example" 0 passing (11ms) 2 failing 1) GraphQL example "before all" hook in "GraphQL example": Error: listen EADDRNOTAVAIL: address not available 172.28.0.4:1234 at Server.setupListenHandle [as _listen2] (node:net:1355:21) at listenInCluster (node:net:1420:12) at GetAddrInfoReqWrap.doListen (node:net:1559:7) at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:74:8) 2) GraphQL example "after all" hook in "GraphQL example": Error: The pact mock service wasn't running when finalize was called at Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:183:9) at Context.<anonymous> (src/consumer.spec.ts:33:26) at processImmediate (node:internal/timers:466:21)```

agustin.gomes
2022-03-22 17:25
I must mention that I'm fairly new to the JS ecosystem, so apologies in advance if I missed anything seemingly obvious. Also, I used the graphql example to set up the node app part: https://github.com/pact-foundation/pact-js/tree/master/examples/graphql

seasharp37
2022-03-22 22:17
has joined #pact-js

matt.fellows
2022-03-23 02:24
You don?t need Ruby to run Pact. It?s bundled in the npm package and should be invisible to you

matt.fellows
2022-03-23 02:24
I wouldn?t recommend this setup

matt.fellows
2022-03-23 02:24
Why did you think you needed ruby?

saritacutinha
2022-03-23 07:09
has joined #pact-js

agustin.gomes
2022-03-23 08:43
The errors I was getting hinted me in that direction. In any case, I'm happy to report I managed to make it work, but instead the `new Pact` used in the graphQL example I linked, I used `new PactWeb` and it worked nicely with the rest of the example. Thank you for your feedback so far @matt.fellows

matt.fellows
2022-03-23 08:48
hmm that?s strange

matt.fellows
2022-03-23 08:48
you shouldn?t need to use PactWeb, and we?re currently planning on decommissioning/stop support for it going forward

matt.fellows
2022-03-23 08:49
That would indicate there are issues starting the mock server - it could even be a port conflict

matt.fellows
2022-03-23 08:49
setting log level to debug and sharinsg the output might be helpful

rachelb
2022-03-23 10:16
has joined #pact-js

agustin.gomes
2022-03-23 14:01
> it could even be a port conflict I think it's unlikely. The mock server is brought up outside the node ecosystem. From this part of the message I posted above: ```Error: listen EADDRNOTAVAIL: address not available 172.28.0.4:1234``` I get the feeling Node is trying to start the server without checking if the server is already reachable.

agustin.gomes
2022-03-23 14:02
> setting log level to debug and sharinsg the output might be helpful I'll try to recreate the situation further.

agustin.gomes
2022-03-23 14:04
> you shouldn?t need to use PactWeb, and we?re currently planning on decommissioning/stop support for it going forward The `PactWeb` I'm refering still part of the `@pact-foundation/pact` package, not the `@pact-foundation/pact-web`

edouard.lopez
2022-03-23 16:51
Could you elaborate on the use case for using matcher in the request definition (e.g. `withRequest`). We are in the process of deploying Pact internally and people are this for the wrong reason (e.g. copy/pasting code) https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js#L180

david.uzumaki
2022-03-23 19:32
hi @caiquedpfc for your graphql api provider, is the actual query string being sent when you try to verify the pact? I wrote a consumer test and I?m trying to setup a provider for graphql queries but when investigating the response to my local provider endpoint, It seems pact doesn?t actually send the graphql query string? not sure if it?s me or that?s intended behaviour

david.uzumaki
2022-03-23 19:33
At the end of the day it?s just a post request with data but the data doesn?t seem to contain the actual query string from the pact file

david.uzumaki
2022-03-23 19:34
an example interaction in the pact file: ```"interactions": [ { "description": "blah blah", "providerState": "blah blah", "request": { "method": "post", "path": "/v1/graphql/", "headers": { "Content-Type": "application/json", "Authorization": "eyJ..." }, "body": { "query": "some query" <--- this isn't being sent to the provider when attempting to verify with provider } },```

david.uzumaki
2022-03-23 19:35
did you ever encounter this issue? @caiquedpfc

matt.fellows
2022-03-23 21:27
> The mock server is brought up outside the node ecosystem. the port conflict has nothing to do with where the conflict happens - in or out or node

matt.fellows
2022-03-23 21:27
I?d like to see your configuration for Pact vs how you are starting the mock server yourself

matt.fellows
2022-03-23 21:28
This looks like a different internal network. Are you hard coding the port to `1234` ? If so, you need to make sure you can a) bind to that port b) it?s free and c) the address you want to bind is corrrect. `172.28.0.4:1234` Looks like you?re not using dynamic port allocation (i.e. you?re hard coding `1234` as the port). Drop the hard coding and it should pick a random free one for you

matt.fellows
2022-03-23 21:29
It?s rarely needed IRL

matt.fellows
2022-03-23 21:29
I?d not use it unless you must

matt.fellows
2022-03-23 21:29
I think it?s there, because in this e2e it shows most of the ways you can use all of the things

shaheen
2022-03-23 23:11
has joined #pact-js

edouard.lopez
2022-03-24 10:28
Thanks, that remove the doubts I had

bernard
2022-03-24 11:52
:wave: Hi, I'm seeing this on a passing test. ```pact-node@10.17.2: Pact Binary Error: WARN: No content type found, performing text diff on body``` Any ideas? After a google search I wasn't able to work out how to remove this error from the output of the test run.

sentyaev
2022-03-24 12:36
has joined #pact-js

altan.demirkiran
2022-03-24 14:06
has joined #pact-js

matt.fellows
2022-03-24 20:45
You should explicitly set the `content-type` header

matt.fellows
2022-03-24 20:45
(on the request/response, whichever is not being set on)

jonathan.fortunati
2022-03-24 21:53
has joined #pact-js

simon.dicola
2022-03-25 10:25
has joined #pact-js

mrooschuz
2022-03-25 14:52
has joined #pact-js

ashok.pathak
2022-03-25 15:17
has joined #pact-js

rdanthuluri
2022-03-27 03:28
has joined #pact-js

rdanthuluri
2022-03-27 04:09
Hi Team . i am trying to implement pact test with type script. i am facing below issue . could u please help me to resolve the issue

matt.fellows
2022-03-27 04:14
Based on that, it looks like you're not sending the request to the actual mock service. It's probably still sending requests to the real service

rdanthuluri
2022-03-27 04:20
this is my spec.ts file

rdanthuluri
2022-03-27 04:21
can you please give me some details on mock service

matt.fellows
2022-03-27 04:32
Please review and then provide the log file

rdanthuluri
2022-03-27 04:35
Sure Matt. thank you

cudi.unal
2022-03-28 11:25
has joined #pact-js

ashraf.anwar.iw
2022-03-28 13:12
has joined #pact-js

b.costa
2022-03-28 13:15
has joined #pact-js

mark.hopper
2022-03-28 14:53
has joined #pact-js

mark.hopper
2022-03-28 14:57
~Good afternoon all, I was wondering if someone could help me? I?m trying to get the angular side of our pact tests running in a Gitlab CI/CD Docker Container based off the Node Alpine image (node:17-alpine). I?ve already followed the various threads and ensured that relevant dependencies (such as bash) are installed as part of the pipeline. When it runs, I?m seeing this error Error: Error: connect ECONNREFUSED ::1:2754 ? I?ve ran it in Trace Logging mode and it would appear that the mock service is running ? is there any hints or tips someone could give me to try and diagnose this?~ I ended up changing it from http://localhost:2754 to http://127.0.0.1:2574 and this is now working

ashraf.anwar
2022-03-28 15:08
has joined #pact-js

agustin.gomes
2022-03-28 15:51
Hi Matt, here is the docker-compose I'm using: ```services: app: build: context: /home/agustingomes/pact-project-poc dockerfile: ./.docker/Dockerfile.node.alpine container_name: contract-test environment: PACT_CONSUMER_NAME: instapro-client PACT_MOCK_SERVER_HOST: 127.0.0.1 PACT_MOCK_SERVER_PORT: '1234' PACT_PROVIDER_NAME: pocProvider hostname: contract-test network_mode: host volumes: - /home/agustingomes/pact-project-poc/contract-tests-poc:/var/www/html:rw working_dir: /var/www/html pact-mock-provider: command: > mock-service --port 1234 --host 0.0.0.0 --pact-dir=/tmp/pacts --consumer=pocConsumer --provider=pocProvider --log=/tmp/pacts/mock-provider.log --log-level=debug --pact-specification-version=2.0.0 --pact-file-write-mode=overwrite container_name: pact-mock-provider expose: - '1234' hostname: pact-mock-provider image: pactfoundation/pact-cli:0.50.0.19 ports: - published: 1234 target: 1234 volumes: - /home/agustingomes/pact-project-poc/pacts:/tmp/pacts:rw working_dir: /pact version: '3.8'``` I start the Mock provider with: ```docker-compose up -d pact-mock-provider``` And then, I run the test via the `app` service I defined in my docker-compose: ```docker-compose run --rm app npm run test:contract``` And finally, this is how the provider in the test is set up: ```import { PactWeb } from "@pact-foundation/pact/src/pact-web" . . . const provider = new PactWeb({ host: process.env.PACT_MOCK_SERVER_HOST || "", port: parseInt(process.env.PACT_MOCK_SERVER_PORT || ""), log: "stderr", logLevel: "debug", }) . . .``` With this setup, I am able to generate the contract: ``` > mocha src/consumer.spec.ts Setting up Pact using mock service on port: "1234" (node:18) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) GraphQL login login via /graphql ? returns a valid token 1 passing (27ms)``` Let me know if I can provide you more details

damianruizdev
2022-03-28 18:44
has joined #pact-js

david.uzumaki
2022-03-28 19:32
update: I realised it sends a second request to the real provider endpoint with the body in that data there in addition I?ve opted to have my pact tests completely ignore my authorization middleware those are handled by other integration tests

damianruizdev
2022-03-28 19:35
Hey everyone, our company is currently trying to integrate Pact into our nx monorepo and we keep running into errors when trying to run the tests. Was curious if anyone has ever integrated Pact into an nx monorepo that uses angular, jest, and cypress. The initial error we're running into is jest and cypress types clashing when running the Pact test. Our monorepo is configured to support both jest/cypress and we have jest tests in other libs that run fine so not sure what about Pact is causing this behavior. (edited)

yousafn
2022-03-28 19:40
Hey @damianruizdev, I've not used nx before but I also maintain a couple of cypress packages and have had people with nx monorepos having various issues raised on my projects I know there is at least one user with nx in pact-js https://github.com/pact-foundation/pact-js/issues/731#issuecomment-900786756, they are on our v3 version, but haven't seen much else If you have some time to setup a repro project, it would be interesting to identify if the test run fine in `nx` without cypress, if so, then it may just be a typescript config issue,

sebastianman45
2022-03-28 19:59
Hello Team :wave::sunglasses:, a question, I am trying to run my pact project on a mac machine with big sur 11.6.2 operating system, and I am having problems on the provider side, pact throws a generic error, I have not found the possible cause; the log is the following, Do you know why it could have this behavior?:

sebastianman45
2022-03-28 19:59
the complete log is above: ```[2022-03-28 19:31:45.402 +0000] INFO (96647 on WM-C02DX5CZMD6T): pact@10.0.0-beta.56: Verifying provider [2022-03-28 19:31:45.409 +0000] INFO (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Verifying Pacts. [2022-03-28 19:31:45.410 +0000] INFO (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Verifying Pact Files [2022-03-28 19:31:45.410 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Initalising native core at log level 'debug' [2022-03-28 19:31:45.412 +0000] WARN (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Ignoring option 'consumerVersionTags' because it is invalid without 'pactBrokerUrl' also being set. This may indicate an error in your configuration [2022-03-28 19:31:45.412 +0000] WARN (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Ignoring option 'publishVerificationResult' because it is invalid without 'pactBrokerUrl' also being set. This may indicate an error in your configuration [2022-03-28 19:31:45.414 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: sending arguments to FFI: [2022-03-28 19:31:45.415 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: --request-timeout 30000 --loglevel debug --state-change-url http://localhost:60534/_pactSetup --provider-tags QA --provider-version 1.0.0 --port 60534 --hostname localhost --provider-name getidentityProvider --file /Users/jsuarezp/tr/__tests__/contract/pacts/getidentityConsumer-getidentityProvider.json RUNS __tests__/contract/provider/identity/get.identity.provider.spec.js [2022-03-28T19:31:45Z DEBUG pact_ffi::verifier::verifier] Pact source to verify = File(/Users/jsuarezp/tr/__tests__/contract/pacts/getidentityConsumer-getidentityProvider.json) [2022-03-28T19:31:45Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries: core/content-generator/binary core/content-generator/json core/content-matcher/json core/content-matcher/multipart-form-data core/content-matcher/text core/content-matcher/xml [2022-03-28T19:31:45Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries: core/matcher/v1-equality core/matcher/v2-max-type core/matcher/v2-min-type core/matcher/v2-minmax-type core/matcher/v2-regex core/matcher/v2-type core/matcher/v3-content-type core/matcher/v3-date core/matcher/v3-datetime core/matcher/v3-decimal-type core/matcher/v3-includes core/matcher/v3-integer-type core/matcher/v3-null core/matcher/v3-number-type core/matcher/v3-time core/matcher/v4-array-contains core/matcher/v4-equals-ignore-order core/matcher/v4-max-equals-ignore-order core/matcher/v4-min-equals-ignore-order core/matcher/v4-minmax-equals-ignore-order core/matcher/v4-not-empty RUNS __tests__/contract/provider/identity/get.identity.provider.spec.js thread '<unnamed>' panicked at 'Client::new(): reqwest::Error { kind: Builder, source: MissingOrMalformedExtensions }', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/reqwest-0.11.9/src/async_impl/client.rs:1263:38 [2022-03-28 19:31:46.106 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: response from verifier: null, 3 [2022-03-28 19:31:46.107 +0000] ERROR (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: !!!!!!!!! PACT CRASHED !!!!!!!!! The underlying pact core crashed in an unexpected way. This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it. There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output. SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world. We're sorry about this! FAIL __tests__/contract/provider/identity/get.identity.provider.spec.js Validate pact of identity ? validate the pact of an identity get (706 ms) ? Validate pact of identity ? validate the pact of an identity get Pact Verification FAIL!: Get identity 22 | console.log('Pact Verification Complete!: Get identity ', res); 23 | }).catch((res) => { > 24 | throw new Error('Pact Verification FAIL!: Get identity ', res); | ^ 25 | }); 26 | }) 27 | at __tests__/contract/provider/identity/get.identity.provider.spec.js:24:23```

damianruizdev
2022-03-28 20:31
Awesome, thanks yousaf! I'll look into this tomorrow and get back to you :slightly_smiling_face:

matt.fellows
2022-03-28 21:54
Look, you can do it that way, but as I said, we?re going to be removing the `PactWeb` interface going forward, and it?s a clumsy setup. I?d like to know why you need to manually run the mock service and you can?t just run the tests

matt.fellows
2022-03-28 21:54
if you could share a reproducible code base, I could run it to see why it doesn?t work

matt.fellows
2022-03-28 21:55
You can do what you?re doing above, I?m just giving you the forewarning that it means you will unlikely be able to upgrade to the next major release without rework

matt.fellows
2022-03-28 21:59
Ah, I think this is related to an invalid certificate in your chain


matt.fellows
2022-03-28 22:01
It looks like it?s still not released yet, but when it is it will resolve this issue

matt.fellows
2022-03-28 22:02
for now, there is a certificate in your chain somewhere that is invalid, you?ll need to find which one it is and remove/fix it

agustin.gomes
2022-03-29 08:06
> if you could share a reproducible code base, I could run it to see why it doesn?t work I will put together the example I have. Will do it in 2 commits. the first one with `PactWeb`, and the second with `Pact`.

matthew.churcher
2022-03-29 08:48
has joined #pact-js

matt.fellows
2022-03-29 09:28
Thanks!

matt.fellows
2022-03-29 09:28
note I?m off for a few days, but if you raise an issue at the pact-js repo I can take a look when back (or another maintainer might be able to check also)

agustin.gomes
2022-03-29 13:03
no rush. Enjoy your days off @matt.fellows and thanks for bearing with me :raised_hands:

ben.brugman
2022-03-29 14:32
has joined #pact-js

hassan.shaikley
2022-03-29 16:14
has joined #pact-js

oakkub.1995
2022-03-30 07:10
has joined #pact-js

adrian.ernst.lgln
2022-03-30 13:03
Hello everyone im currently writing a pact test for an endpoint that returns a file i want to download. I can't seem to find a matcher for binary data and adding binary to Matchers.somethinglike() doesnt seem to work. Is the right practice here to just not add a body to the willRespondWith Object?

sebastianman45
2022-03-30 14:34
Thank you very much, Matt :raised_hands:, checking I have several expired certificates on my machine, I will manage them and validate it again

hiqbal
2022-03-30 15:16
has joined #pact-js

sstenhouse
2022-03-30 15:16
has joined #pact-js

bmeyres
2022-03-30 17:37
has joined #pact-js

sebastianman45
2022-03-30 18:18
Hello Team :wave::sunglasses:, one question, is Pact js V3 already compatible with jest?, I am trying to use `stateHandlers` with `(setup, parameters)` but the value of these parameters is undefined, I want to do something like this: (I'm using the 10.0.0-beta.58 version of pact), thanks :raised_hands::

alejandro.velez
2022-03-30 18:42
has joined #pact-js

justin
2022-03-30 20:07
has joined #pact-js

matt.fellows
2022-03-30 21:42
Check out the latest v3 beta

matt.fellows
2022-03-30 21:42
But if you want to do a type match on binary just drop the payload and look at the headers only

rdanthuluri
2022-03-30 22:05
Hi Team

rdanthuluri
2022-03-30 22:05
my js file is having one test when i run the test to generate contract is failing at after each hook

rdanthuluri
2022-03-30 22:06
consumer@1.0.0 pacts C:\UIEN-Local\pact-test\pact-test > mocha --recursive "tests/*.pact.js" --timeout 100000 [2022-03-30T22:04:07.287Z] INFO: pact-node@10.9.4/13532 on PC0X2B10: Creating Pact Server with options: {"consumer":"React","cors":false,"dir":"C:\\UIEN-Local\\pact-test\\pact-test\\pacts","host":"127.0.0.1","log":"C:\\UIEN-Local\\pact-test\\pact-test\\logs\\pact.log","pactFileWriteMode":"overwrite","port":1234,"provider":"token","spec":2,"ssl":false} Consumer Test [2022-03-30T22:04:08.891Z] INFO: pact@9.11.0/13532 on PC0X2B10: Setting up Pact with Consumer "React" and Provider "token" using mock service on Port: "1234" ? OK response Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /modules See C:/UIEN-Local/pact-test/pact-test/logs/pact.log for details. (node:13532) UnhandledPromiseRejectionWarning: AssertionError: expected 'OK ' to equal 'OK' at C:\UIEN-Local\pact-test\pact-test\tests\consumer.pact.js:55:47 at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:13532) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:13532) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 1) "after each" hook for "OK response" [2022-03-30T22:04:08.973Z] INFO: pact@9.11.0/13532 on PC0X2B10: Pact File Written [2022-03-30T22:04:08.973Z] INFO: pact-node@10.9.4/13532 on PC0X2B10: Removing Pact process with PID: 9936 [2022-03-30T22:04:09.152Z] INFO: pact-node@10.9.4/13532 on PC0X2B10: Deleting Pact Server with options: {"consumer":"React","cors":false,"dir":"C:\\UIEN-Local\\pact-test\\pact-test\\pacts","host":"127.0.0.1","log":"C:\\UIEN-Local\\pact-test\\pact-test\\logs\\pact.log","pactFileWriteMode":"overwrite","port":1234,"provider":"token","spec":2,"ssl":false} 1 passing (2s) 1 failing 1) Consumer Test "after each" hook for "OK response": Error: Pact verification failed - expected interactions did not match actual. at new VerificationError (node_modules\@pact-foundation\pact\errors\verificationError.js:19:42) at C:\UIEN-Local\pact-test\pact-test\node_modules\@pact-foundation\pact\httpPact.js:102:23 at processTicksAndRejections (internal/process/task_queues.js:97:5) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! consumer@1.0.0 pacts: `mocha --recursive "tests/*.pact.js" --timeout 100000` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the consumer@1.0.0 pacts script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\radha.danthuluri\AppData\Roaming\npm-cache\_logs\2022-03-30T22_04_09_197Z-debug.log

rdanthuluri
2022-03-30 22:07
please suggest how to resolve this error

matt.fellows
2022-03-30 22:48
9 times out of ten this is because you're not sending requests to the pact mock server

leo.adriano1994
2022-03-31 00:00
has joined #pact-js

hitesh.patadia
2022-03-31 04:27
has joined #pact-js

matt.cockayne
2022-03-31 11:02
has joined #pact-js

jimmy
2022-03-31 15:39
has joined #pact-js

bret.mcclory538
2022-04-01 01:10
has joined #pact-js

michael.d
2022-04-01 04:40
has joined #pact-js

yash.deole
2022-04-01 07:07
has joined #pact-js

matt.fellows
2022-04-01 07:58
@artur sorry for the delay. This should have your fixes

alan.alie
2022-04-01 08:10
has joined #pact-js

jimmy
2022-04-01 08:11
@jimmy has left the channel

alan.alie
2022-04-01 08:28
set the channel topic: Questions and updates about Pact in JS/TS/node. See also #pact-js-development for contribution or development questions. All questions welcome!

alan.alie
2022-04-01 10:09
Hi all, I?ve previously written pact tests using *axios* as the http handler but the consumer app itself uses *fetch* (from node-fetch) instead. I?ve tried to switch to using fetch but hit problems. I understand that using *jest-pact* is a possible solution so I?ve implemented the following example: ```import { URL } from 'url'; import { Matchers } from '@pact-foundation/pact'; import { HTTPMethod } from '@pact-foundation/pact/src/common/request'; import { pactWith } from 'jest-pact'; import fetch from 'node-fetch'; jest.setTimeout(30000); pactWith({ consumer: 'aggregator', provider: 'theme_provider' }, (provider) => { describe('Theme related end points', () => { it('Request to save themes', async () => { const url = new URL(`${provider.mockService.baseUrl}/themes-service/themes`); const { validateExample } = Matchers; const interaction = { state: 'Request to save themes', uponReceiving: 'Request to save themes', withRequest: { method: http://HTTPMethod.POST, path: url.pathname, headers: { Accept: 'application/json' }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: { results: [{ handle: 'abc', result: 'Created' }], }, }, }; await provider.addInteraction(interaction); const result = await fetch(`${provider.mockService.baseUrl}/themes-service/themes`, { method: http://HTTPMethod.POST, headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }); expect(await result.json()).toEqual({ results: [ { handle: 'abc', result: 'Created', }, ], }); }); }); });``` Unfortunately, I get the following error: ``` FAIL __pact__/fetch2.pact.spec.ts (10.793 s) Pact between aggregator and theme_provider with 30000 ms timeout for Pact Theme related end points ? Request to save themes (59 ms) ? Pact between aggregator and theme_provider ? with 30000 ms timeout for Pact ? Theme related end points ? Request to save themes FetchError: invalid json response body at reason: Unexpected end of JSON input 42 | }); 43 | > 44 | expect(await result.json()).toEqual({ | ^ 45 | results: [ 46 | { 47 | handle: 'abc', at node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:273:32 at Object.<anonymous> (__pact__/fetch2.pact.spec.ts:44:20)``` If I remove `await` from the offending line of code then the test fails because the response promise never gets fulfilled :confused: ``` FAIL __pact__/fetch2.pact.spec.ts (12.368 s) Pact between aggregator and theme_provider with 30000 ms timeout for Pact Theme related end points ? Request to save themes (65 ms) ? Pact between aggregator and theme_provider ? with 30000 ms timeout for Pact ? Theme related end points ? Request to save themes expect(received).toEqual(expected) // deep equality - Expected - 8 + Received + 1 - Object { - "results": Array [ - Object { - "handle": "abc", - "result": "Created", - }, - ], - } + Promise {} 42 | }); 43 | > 44 | expect(result.json()).toEqual({ | ^ 45 | results: [ 46 | { 47 | handle: 'abc', at Object.<anonymous> (__pact__/fetch2.pact.spec.ts:44:35)``` What am I missing or overlooking? I'd be really grateful for any assistance on this problem :slightly_smiling_face:

matt.fellows
2022-04-01 10:18
What do the mock server logs say they received?

matt.fellows
2022-04-01 10:19
It's possible cors is the issue

alan.alie
2022-04-01 10:27
Hi Matt, not sure where to find the logs for the mock server.

alan.alie
2022-04-01 10:27
Is that the `pact.log` file?

alan.alie
2022-04-01 10:46
I've added the following to the provider setup ``` log: path.resolve(process.cwd(), '__pact__/logs', 'pact-fetch.log'), logLevel: 'debug', cors: true,``` ....and the output looks like this ``` FAIL __pact__/fetch2.pact.spec.ts (10.086 s) Pact between aggregator and theme_provider with 30000 ms timeout for Pact Theme related end points ? Request to save themes (84 ms) ? Pact between aggregator and theme_provider ? with 30000 ms timeout for Pact ? Theme related end points ? Request to save themes expect(received).toEqual(expected) // deep equality - Expected - 8 + Received + 1 - Object { - "results": Array [ - Object { - "handle": "abc", - "result": "Created", - }, - ], - } + Promise {} 51 | }); 52 | > 53 | expect(result.json()).toEqual({ | ^ 54 | results: [ 55 | { 56 | handle: 'abc', at Object.<anonymous> (__pact__/fetch2.pact.spec.ts:53:39)``` ....and the `pact.log` file looks like this ```I, [2022-04-01T11:43:11.829104 #62695] INFO -- : Registered expected interaction POST /themes-service/themes D, [2022-04-01T11:43:11.829281 #62695] DEBUG -- : { "description": "Request to save themes", "providerState": "Request to save themes", "request": { "method": "POST", "path": "/themes-service/themes", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "results": [ { "handle": "abc", "result": "Created" } ] } }, "metadata": null } W, [2022-04-01T11:43:11.844186 #62695] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /themes-service/themes W, [2022-04-01T11:43:11.844236 #62695] WARN -- : Missing requests: POST /themes-service/themes I, [2022-04-01T11:43:11.895725 #62695] INFO -- : Cleared interactions```

alan.alie
2022-04-01 10:54
I've located the mock server log aggregator-theme_provider-mockserver-interaction.log and it has the following ```W, [2022-04-01T11:03:36.800180 #58467] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /themes-service/themes W, [2022-04-01T11:03:36.800294 #58467] WARN -- : Missing requests: POST /themes-service/themes```

alan.alie
2022-04-01 11:25
I've set `cors` to both *true* and *false* with no effect :confused:


alan.alie
2022-04-01 11:28
@matt.fellows is it possible that the json response data isn't being extracted from the promise correctly?

rdanthuluri
2022-04-01 11:53
Thanks Matt for the response

ricardo.cruz
2022-04-01 11:54
has joined #pact-js

thomas.fisher
2022-04-01 12:15
has joined #pact-js

lauren.corderoy
2022-04-01 12:24
has joined #pact-js

jiayao.xu
2022-04-01 12:24
has joined #pact-js

bret.mcclory538
2022-04-01 14:36
@bret.mcclory538 has left the channel

shiva.velde0413
2022-04-01 14:44
has joined #pact-js

damianruizdev
2022-04-01 17:54
Hey everyone, happy Friday! Do we know if anyone has ever integrated Pact testing into an NX monorepo with Cypress and Jest?

matt.fellows
2022-04-01 22:07
That error is pretty clear - the fetch call didn't send the request to the expected path. My guess is it's something to do with running fetching in a node process

artur
2022-04-04 04:05
thank you that unblocks me

npc1222
2022-04-04 04:37
has joined #pact-js

artur
2022-04-04 05:45
with https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.59 it seems not to be possible to have in one interaction multiple provider states with the same name. That was possible in .36. Is that a bug or a feature? My use-case is to create multiple files. So I call multiple times ` ```provider.given('file exists', { username, password, fileName: resource })``` but in the JSON I only have one providerstate with that name ``` "providerStates": [ { "name": "the user is recreated", "params":... }, { "name": "file exists", "params": { "fileName": "testFolder/??.txt", "password": "test123", "username": "test123" } }, { "name": "resource is shared", "params": ... } ]``` Making the names of provider states individual makes them appear in the JSON, but that would mean I would also have to have an individual state definition in the provider tests (stateHandlers)

matt.fellows
2022-04-04 05:47
hmmm it seems like that would have been a bug in the core that has been resolved (I don?t know why/where just yet). The name of the state I think needs to be unique

matt.fellows
2022-04-04 05:47
@uglyog is my assumption correct? If not, I?ll see if I can track down where that assumption is built in code (whether JS or somewhere else)

uglyog
2022-04-04 05:49
It may have been an accidental feature, I don't recall doing that by design

matt.fellows
2022-04-04 05:49
Should it be possible to have multiple provider states with the same description (but different params?)

uglyog
2022-04-04 05:50
But then it has been a while, and maybe I just don't recall what I was doing back then

matt.fellows
2022-04-04 05:50
I assume not

artur
2022-04-04 05:51
if the same description is not allowed, then my tests cannot have just arbitrary filenames, but the names have to be part of the description, or some kind of counter is needed

uglyog
2022-04-04 05:51
The provider states are not keyed, so you could have multiple in the Pact file with the same description. I don't know what the effect will be. But I assume it will just loop though the list and call the handler based on the name

artur
2022-04-04 05:52
that would be my expectation

uglyog
2022-04-04 05:52
Just checked Pact-JVM, uniqueness is description + parameters

matt.fellows
2022-04-04 05:53
Cool. I'll see if I can track down where the issue is

matt.fellows
2022-04-04 05:53
It might be there is a keyed state somewhere so it's overridden

matt.fellows
2022-04-04 05:53
Your use case makes sense actually

artur
2022-04-04 05:55
the stateHandler on the provider side is happy with the same names, just loops. So the issue is on the side of writing to the JSON

bernard
2022-04-04 08:38
Looking at the output below... Is this because there are no verification tests for the provider? So the can-i-deploy says no. ``` View the published pact at https://grabyo-test.pactflow.io/pacts/provider/studio-backend/consumer/studio-frontend/version/b5309ddca0%2B1648824839 Events detected: contract_published (pact content is the same as previous version with tag PLAT-1697-pact-demo and no new tags were applied), contract_requiring_verification_published (pact content is the same as previous version with tag PLAT-1697-pact-demo and no new tags were applied) Next steps: * Add Pact verification tests to the studio-backend build. See https://docs.pact.io/go/provider_verification * Configure separate studio-backend pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks ========== STAGE: can-i-deploy? ========== Computer says no ¯_(?)_/¯ No pacts or verifications have been published for version b5309ddca0+1648824845 of studio-frontend```

alan.alie
2022-04-04 08:48
Hi @matt.fellows, is this a known issue between pact-js and fetch? Any other advice on how to proceed with this issue?

bernard
2022-04-04 09:18
Thanks!

matt.fellows
2022-04-04 09:24
I'm not aware of any issues

matt.fellows
2022-04-04 09:24
If you could pls create a repro we can take a look

matt.fellows
2022-04-04 09:27
The version is different between publish and deploy

matt.fellows
2022-04-04 09:29
You're asking to deploy a version of the consumer Pactflow doesn't know about

bernard
2022-04-04 09:30
How can I get Pactflow to know about it?

matt.fellows
2022-04-04 09:31
By publishing a pact for it!

bernard
2022-04-04 09:31
I can see this in the output... ```Pact successfully published for studio-frontend version b5309ddca0+1649064121 and provider studio-backend.```

matt.fellows
2022-04-04 09:31
I think you have a flaw in your pipeline the version is not deterministic

matt.fellows
2022-04-04 09:32
Yes, but look at the version. It's different when you call can I deploy

bernard
2022-04-04 09:32
Ah I see, I'll take a look at that.

matt.fellows
2022-04-04 09:32
So you publish for one version and then ask to deploy another. Hence the output

matt.fellows
2022-04-04 09:32
:+1:

bernard
2022-04-04 09:39
Do you have any idea why the commit would change? I'm using a Makefile and the command I'm running to get the Git commit is: ```GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s````

bernard
2022-04-04 09:47
Thanks @matt.fellows I've fixed it.

alan.alie
2022-04-04 09:56
Hi @matt.fellows Looks like we got to the bottom of our problem with using fetch and pact-js.

alan.alie
2022-04-04 09:59
It turns out that, in the unit tests, we're using *jest-fetch-mock* so our pact tests were calling a mocked fetch to begin with.

alan.alie
2022-04-04 10:00
In our pact tests we've added the following lines to disable *fetchMock*: ```import fetchMock from 'jest-fetch-mock'; ... ... beforeAll(async () => { fetchMock.disableMocks(); }); afterAll(async () => { fetchMock.enableMocks(); });```

matt.fellows
2022-04-04 10:10
Yeah it's not the commit, it's the datetime format

matt.fellows
2022-04-04 10:10
Glad to hear

matt.fellows
2022-04-04 10:10
Ha, yes that'll do it :rolling_on_the_floor_laughing:

arthur
2022-04-04 14:28
has joined #pact-js

arthur
2022-04-04 14:33
hi, i have a few questions / thoughts regarding GraphQL contract testing with Pact (JS), and was wondering whether this would be a good place to put them, or whether another channel might be preferred?

yousafn
2022-04-04 15:50
Here is good @arthur

yousafn
2022-04-04 15:50
and welcome

arthur
2022-04-04 15:52
thanks

arthur
2022-04-04 16:00
we're looking at using Pact to give us nice test separation between our front-end clients and our back-end, which provides a GraphQL API for them to use. at the moment, from having experimented with the GraphQLInteraction class in the Pact JS library, it appears as if fairly complete GraphQL query strings need to be provided in order for the Pact mock API server to return the correct response. i have managed to get this working by formatting the query in precisely the right way (e.g. `... on` rather than `...on`, etc.), according to the GraphQL client library we are using (urql), but i feel that this approach seems a little brittle currently. IMO, with GraphQL, the 'contract' is the strongly-typed schema the technology provides, rather than the precise way in which a client interacts with it. putting this another way, if i make a small change to the query a given client makes, i don't feel that should be regarded as a change of contract, yet so far as i can see, this is how the Pact GraphQLInteraction stuff is currently set up. i was wondering whether, rather than providing a full GraphQL query string, it would be possible to build some sort of strongly-typed schema-based resolver for providing the mock API functionality? this could leverage existing tools (e.g. https://www.graphql-code-generator.com), and still capture interactions for playback against the server logic (in the spirit of Pact), but the developer experience might be somewhat nicer and more idiomatic.

arthur
2022-04-04 16:01
we use TS, and the technology for providing strongly-typed GraphQL resolver functions based on the API schema exists, so i think it would be 'possible', however i'm not sure whether this really fits with the philosophy of Pact.

arthur
2022-04-04 16:02
i would be very interested in hearing any thoughts about this.

agastiya.mohammad
2022-04-05 01:19
has joined #pact-js

matt.fellows
2022-04-05 02:07
Yes

matt.fellows
2022-04-05 02:07
Pact is a specification by example testing framework

matt.fellows
2022-04-05 02:08
I don?t see Pact ever supporting the kind of proposal you have, but I do see that as a viable approach for the bi-directional contract testing feature of Pactflow

matt.fellows
2022-04-05 02:08
What you?re proposing is more of a schema comparison approach, which is different to the way Pact works and will likely ever work

paul.stapleton
2022-04-05 07:33
has joined #pact-js

arthur
2022-04-05 08:09
thanks for your thoughts. given what you say, it sounds like Pact might not be quite the right tool for testing GraphlQL APIs in this way.

arthur
2022-04-05 08:10
i may look into building something more well-suited to its features.

matt.fellows
2022-04-05 08:17
no problems

matt.fellows
2022-04-05 08:17
It?s something we?ll explore for sure in Pactflow

matt.fellows
2022-04-05 08:17
I?d also suggest having a read of https://pactflow.io/blog/schemas-are-not-contracts/ so you can understand the challenges in your approach

matt.fellows
2022-04-05 08:18
(It?s not to say you shouldn?t do it, but just be aware of the elements of contract testing you?ll miss out on)

arthur
2022-04-05 08:21
i will, thanks. i think the main issue i can see with regarding a specific example as canonical is that in GraphQL, it's possible for a client to request things such as field name mappings (e.g. 'firstName' from 'name'), and i see these as not fundamentally changing the contract between the two systems; they're really just metadata of a request.

arthur
2022-04-05 08:22
in practical terms, these sorts of things would normally be handled by the GraphQL server library in use (e.g. Apollo), so application code would not be affected by a change of field name mapping, ergo regarding it as a different example would seem wrong.

matt.fellows
2022-04-05 09:12
Can you please elaborate on this? How does the evolution of this happen? So a provider can rename a field and old referencew are resolved by Apollo?


arthur
2022-04-05 09:49
when consuming a GraphQL API, consumers can describe the 'shape' of the data they want to be returned

arthur
2022-04-05 09:49
this includes the selection and names of fields, as well as more complex things

arthur
2022-04-05 09:51
if, for some reason, a given consumer wants to change the name of a field it receives from the API (as with the name->firstName example i gave earlier), this is something which would be transparent to the provider implementation

arthur
2022-04-05 09:51
as typically it would be handled entirely by GraphQL server libraries such as Apollo

arthur
2022-04-05 09:53
my point is that this sort of consumer-specific change is not a change of contract, IMO, but the string-matching approach taken by GraphQLInteraction in Pact JS currently regards it as such.

iurisoares1012
2022-04-05 09:53
has joined #pact-js

gocool9996
2022-04-05 10:04
has joined #pact-js

matt.fellows
2022-04-05 10:22
> if, for some reason, a given consumer wants to change the name of a field it receives from the API (as with the name->firstName example i gave earlier), this is something which would be transparent to the provider implementation I don?t see how this wouldn?t break any type of contract. Either, the provider has the field or it doesn?t. If it gets renamed in the process by the consumer, sure, that?s up to them and is outside the scope of any contract test (Pact included)

matt.fellows
2022-04-05 10:23
But I think you?re saying, in GraphQL you can change the query which affects the client side (e.g. a field alias). That?s an unfortunate side effect of Pact?s approach, yes

arthur
2022-04-05 10:25
yes; in practical terms, if i write a test that causes a client to make a GraphQL API call which is subsequently mocked / stubbed / recorded by Pact, this is effectively a snapshot of the actual text of the query, which feels brittle to me for the reasons i've outlined.

arthur
2022-04-05 10:25
a subsequent change to that query which has no practical impact on any other system should not then be regarded as a change of contract, IMO.

matt.fellows
2022-04-05 10:26
I think that?s fair, but it?s hard to make Pact perfect in this case to suit all types of APIs

arthur
2022-04-05 10:26
or more accurately, i think that currently Pact does not support GraphQL in an idiomatic way

matt.fellows
2022-04-05 10:26
I think this is an edge case that is more of a theoretical issue than a real one.

matt.fellows
2022-04-05 10:26
> or more accurately, i think that currently Pact does not support GraphQL in an idiomatic way this is definitely true

matt.fellows
2022-04-05 10:27
I would prefer to see us properly handle the AST rather than the current string based approach

matt.fellows
2022-04-05 10:27
https://github.com/pact-foundation/pact-plugins will be where this gets properly solved

matt.fellows
2022-04-05 10:27
This will be a content type plugin

arthur
2022-04-05 10:28
interesting - i think we already have the tooling required to support this sort of behaviour, though i'm not 100% sure how well this would fit with the recording of a given interaction.

arthur
2022-04-05 10:28
there's a slight tension between the requirement to mock a GraphQL API in an elegant way, and the recording of a specific interaction for playback against a provider

matt.fellows
2022-04-05 10:29
Yes, we?re not a general ?take a schema, make a mock server? tool

arthur
2022-04-05 10:29
no, i understand that

matt.fellows
2022-04-05 10:29
Oh, totally, just agreeing with you :stuck_out_tongue:

arthur
2022-04-05 10:30
i've built something which pretty much does exactly that with our schema, but i was particularly interested in using Pact to avoid the horror of full-stack / 'E2E' tests (and for a few other reasons)

arthur
2022-04-05 10:32
i'll have a think about whether i want to separate out the concerns of automated front-end testing and 'pure' API testing, as i think this may go some way towards solving this slight messiness

arthur
2022-04-05 10:33
my main concern with the former being conciseness, elegance and expressiveness for developers, and with the latter being precision / correctness, i think.

arthur
2022-04-05 10:33
anyway, thanks for your thoughts, i'll stop taking up your time now!

matt.fellows
2022-04-05 10:33
not at all - anytime!

matt.fellows
2022-04-05 10:33
this is helpful for me/us as we look to solving GraphQL better going forward

arthur
2022-04-05 10:34
well, we do quite a bit of automated testing with TS and a GraphQL API from various clients, so by all means yell if you want to chat about anything. I'm no expert in GraphQL (which is a *deep* technology), but i've encountered quite a lot of the common 'gotchas', i think

bernard
2022-04-05 15:22
Hi, I'm testing against the latest stubs after my provider has published a contract. And I'm seeing this in the logs. Stub URL: ```https://<our domain>.http://pactflow.io/pacts/provider/<provider>/consumer/<consumer>/latest/stub/``` Logs: ```I, [2022-04-05T15:18:42.151021 #53] INFO -- : Registered expected interaction POST /api/v2/login W, [2022-04-05T15:18:43.517983 #53] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /api/v2/login``` The tests fail on: ```await mockProvider.verify();```

simrat.sidhu
2022-04-05 16:07
has joined #pact-js

gabriel.brazao
2022-04-05 17:42
has joined #pact-js

jhonataok01
2022-04-05 17:43
has joined #pact-js

andre.mariano
2022-04-05 19:10
has joined #pact-js

alex.zuliqiaer
2022-04-05 20:31
has joined #pact-js

lflores
2022-04-05 20:33
has joined #pact-js

matt.fellows
2022-04-05 21:02
the stubs aren?t for use during your contract tests, you use the local mock server for that

keoma4
2022-04-05 21:17
has joined #pact-js

matt.fellows
2022-04-05 21:36
stubs are for use cases outside of Pact directly (e.g. cypress browser tests)

erick.belf
2022-04-05 21:46
has joined #pact-js

michaele
2022-04-06 03:40
has joined #pact-js

brendan.j.donegan
2022-04-06 07:42
I've just found out one of our teams went off and used Spring Cloud Contract without asking, is there an easy way to get them converted to Pact I can point them to?

matt.fellows
2022-04-06 07:44
I don?t think so, but that?s an interesting question

matt.fellows
2022-04-06 07:45
are they writing it in groovy?

brendan.j.donegan
2022-04-06 07:45
Haven't looked yet :see_no_evil:

brendan.j.donegan
2022-04-06 07:46
Also any easy blurb I can give them as to why they shouldn't be using SCC :grinning:

brendan.j.donegan
2022-04-06 07:47
Realizing this is in the wrong channel too, should have been in #pact-jvm

matt.fellows
2022-04-06 07:52
ah, that?s why I was asking about Groovy - I think if you do use SCC outside of JVM, it?s a bit different

brendan.j.donegan
2022-04-06 07:53
No it's a Springboot project

bernard
2022-04-06 09:54
Oh, I see.

matt.fellows
2022-04-06 10:13
May I ask what gave you the impression they were for use in Pact unit tests?

matt.fellows
2022-04-06 10:13
We might need to address our documentation

artur
2022-04-06 10:44
any news on this? Should I create an issue to track it?

matt.fellows
2022-04-06 11:05
yes please!

guillaume.camus
2022-04-06 12:47
has joined #pact-js

danielglazer123
2022-04-06 19:06
has joined #pact-js

ashish.goyal
2022-04-06 23:14
has joined #pact-js

pennellbeth
2022-04-07 08:04
has joined #pact-js

dominic.gara
2022-04-07 08:57
has joined #pact-js

ivan.cheung
2022-04-07 08:58
has joined #pact-js

omrieyal
2022-04-07 08:58
has joined #pact-js

drakulavich
2022-04-07 08:58
has joined #pact-js

jonoar22
2022-04-07 09:06
has joined #pact-js

josh.king
2022-04-07 09:06
has joined #pact-js

pitas01_lope
2022-04-07 09:35
has joined #pact-js

rarestomos
2022-04-07 09:40
has joined #pact-js

shuba.paripoornam
2022-04-07 09:59
has joined #pact-js

shivam.kumar
2022-04-07 11:00
has joined #pact-js

bernard
2022-04-07 12:39
It just wasn't clear that they shouldn't be used for them.

bernard
2022-04-07 12:39
This was helpful: stubs are for use cases outside of Pact directly (e.g. cypress browser tests)

matt.fellows
2022-04-07 12:58
Thanks Bernard - I think we?ll clarify that on the page. Apologies for the confusion (and also - thanks for coming along and I hope the webinar was helpful!)

dgupta2
2022-04-07 13:26
has joined #pact-js

pankajarora512
2022-04-07 22:50
has joined #pact-js

aruncontacts
2022-04-07 22:54
has joined #pact-js

mira.kim
2022-04-07 23:59
has joined #pact-js

bernard
2022-04-08 10:22
It was helpful, really informative and much simpler to understand and convey to other colleagues afterwards.

bernard
2022-04-08 10:32
:wave: I'm having some issues with an interceptor in Cypress. Route matcher ```POST **/api/v2/login (stubbed) Yes (alias) login (count) -``` The request ```POST https://<our domain>.http://pactflow.io/pacts/provider/<our provider>/consumer/<our consumer>/latest/stub/api/v2/login``` The Cypress test ```const loginResponse = require(`../../../fixtures/login.json`); describe(`Login API`, () => { Cypress.config({ defaultCommandTimeout: 120000 }); beforeEach(() => { cy.intercept( { method: `POST`, url: `**/api/v2/login` }, { statusCode: 200, body: { ...loginResponse }, headers: { "access-control-allow-origin": `*` } } ).as(`login`); <----- The alias cy.visit(`/`); cy.setupPact(`<our consumer>`, Cypress.env(`PACT_PROVIDER`)); }); it(`should log into Studio Frontend`, () => { cy.login( `/api/v2/login`, `user`, `password` ); }); after(() => { cy.usePactWait(`login`); <---- This doesn't match the route }); });``` The error ```Error: CypressError: Timed out retrying after 5000ms: `cy.wait()` timed out waiting `5000ms` for the 1st request to the route: `login`. No request ever occurred.```

alphonse.bendt
2022-04-08 11:44
has joined #pact-js

wim.dupont
2022-04-08 11:49
has joined #pact-js

yousafn
2022-04-08 13:02
Hey @bernard! Thanks for trying out the adapter. What does your `cy.login` method look like? Are you making a a `cy.request` call via your customer `cy.login` method? If so, you would wish to use `cy.usePactRequest` https://github.com/pactflow/pact-cypress-adapter#cyusepactrequestoption-alias-and-cyusepactgetalias--alias

bernard
2022-04-08 13:25
@yousafn My `login` command looks like... ```Cypress.Commands.add(`login`, (api, user, passphrase) => { cy.request({ method: `POST`, url: `${Cypress.env(`PACT_PROVIDER_STUB_URL`)}${api}`, body: { user, passphrase }, headers: { Authorization: `Bearer ${Cypress.env(`PACT_PROVIDER_TOKEN`)}`, Accept: `application/json, text/plain, */*` } }); });```

wilsonmar
2022-04-08 13:41
has joined #pact-js

bernard
2022-04-08 14:05
@yousafn refactored it based on the document you sent over. It's working now. The Pact file is being written. Thanks :pray:

henit.laxmicant
2022-04-08 14:19
has joined #pact-js

yousafn
2022-04-08 14:37
Saweeeeet!

yousafn
2022-04-08 14:38
Props to the author @slin and her documentation :chefkiss:

mateustalles
2022-04-08 17:35
has joined #pact-js

bioflash1
2022-04-11 09:21
has joined #pact-js

artur
2022-04-11 10:27
I'm sometimes getting this error `[2022-04-11T10:08:01Z ERROR pact_js_v3::verify] Verify process failed with a panic: failed printing to stdout: Resource temporarily unavailable (os error 11)` This is with 10.0.0-beta.36 (cannot update currently because of other issues) Any idea what resource could not be availiable?

bernard
2022-04-11 10:41
Hi @yousafn apologies for wrangling your handle. But I have a question. In Cypress can I make a request to the latest stub URL of my integration? And get the OAS schema example for the path back in my response?

yousafn
2022-04-11 12:09
Is there 2 separate questions there? ? In Cypress can I make a request to the latest stub URL of my integration? ? Yes, @lewis.prescott079 made a post recently https://www.pactman.co.uk/post/end-to-end-testing-in-microservices-with-api-contracts ? You can read in also read in a Pact file directly, and strip off the matchers and feed into to cy.route https://gist.github.com/bethesque/a4b117ebb09488c101f88320cac678a4 ? And get the OAS schema example for the path back in my response? ? Not sure I fully understand this? As a response from what?

yousafn
2022-04-11 12:10
Some more info on the first point in our docs https://docs.pact.io/consumer/using_pact_to_support_ui_testing

francislainy.campos
2022-04-11 12:41
Hi, do we have any example on how to use dynamic ids for V3?


matt.fellows
2022-04-11 13:13
hmm that is strange indeed


matt.fellows
2022-04-11 13:14
It seems strange that it would start occurring now though. Perhaps there is an internal inefficiency somewhere in the library

matt.fellows
2022-04-11 13:14
Are you seeing it in CI or locally?

stambolaolya
2022-04-11 13:20
has joined #pact-js

bernard
2022-04-11 13:53
If the provider uses an OAS document which has examples, is it possible to use the latest stub URL as my consumers endpoint. And not have to write Cypress interceptors that make use of fixtures? Instead of using the fixture, I'd like to assert that the response fits the pattern of the OAS response example.

yousafn
2022-04-11 14:03
I don't believe we allow for generating stubs from OAS/Provider Contracts. Sounds like a cool idea though!

bernard
2022-04-11 14:05
It would be helpful. SmartBear through their Swagger Editor provide a stub URL which sends back examples, which I previously used to assert against in my responses.

yousafn
2022-04-11 14:08
Ahh yeah, I can see here https://github.com/OpenAPITools/openapi-generator available in all kinds of flavours of languages > Ada, C# (http://ASP.NET Core, Azure Functions), C++ (Pistache, Restbed, Qt5 QHTTPEngine), Erlang, F# (Giraffe), Go (net/http, Gin, Echo), Haskell (Servant, Yesod), Java (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, https://github.com/ProKarma-Inc/pkmst-getting-started-examples, https://vertx.io/, https://camel.apache.org/), Kotlin (Spring Boot, Ktor, Vertx), PHP (Laravel, Lumen, https://github.com/mezzio/mezzio, Slim, Silex, https://symfony.com/), Python (FastAPI, Flask), NodeJS, Ruby (Sinatra, Rails5), Rust (rust-server), Scala (Akka, https://github.com/finagle/finch, https://github.com/lagom/lagom, https://www.playframework.com/, Scalatra) I previously created one for https://github.com/pact-foundation/serverless-offline-pact that you could feed a pact file into and spin up a stub server, and have also hosted stub servers in ECS via a docker container.

yousafn
2022-04-11 14:09
where would this fit on the consumer side, in terms of their testing pyramid/pipeline?

yousafn
2022-04-11 14:10
Feel free to raise an issue on the Pactflow Roadmap buddy https://github.com/pactflow/roadmap#contributing-to-the-roadmap

bernard
2022-04-11 15:28
Sorry for the late reply....

bernard
2022-04-11 15:28
More questions, sorry.....

bernard
2022-04-11 15:29
The interactions in a Pact that I just queried using CURL responded with the responses crafted by interactions created during Unit Tests.

bernard
2022-04-11 15:30
Would you recommend that the responses to an interaction be crafted based on the OAS in Pactflow?

bernard
2022-04-11 15:31
So I create interactions in my unit tests. And in my e2e Cypress tests use the stubs?

souravmalhotra007
2022-04-11 15:56
has joined #pact-js

akshay.nm92
2022-04-11 17:48
has joined #pact-js

yousafn
2022-04-11 18:14
An OAS is just a design spec, so doesn't represent the subset of interactions any one consumer may have with it. I think the stubs made from Pact servers work fine for the _most_ part, however for some e2e cases, I needed more granular control over my mocks, which tools like Wiremock etc provide (response templating). We also used our stubs in a hosted environment (basically a dev environment where our main services lived, but third party dependencies were mocked out) so the PO's could play around with it, without being reliant on everything being up an integrated test env

yousafn
2022-04-11 18:15
I could see value in standing up a OAS stub server from a spec, especially in Pactflow land as you would have confidence that it was tied to a particular build, or environment. Good for for thought anyway

yousafn
2022-04-11 18:18
I used to create pacts in my consumer code, and prior to uploading them, I would run swagger-mock-validator to ensure we didn't upload any Pacts that were garbage. If consumers or providers wanted to make API changes, they would propose it on a feature branch for the docs, and then when a Pact was generated on the same feature branch, it would pull the corresponding openapi spec, and if not one on the branch it would fall back to master. Our providers used the API specs in their AWS API gateways as request/response validators as well, and we weren't overly confident on their test coverage, but testing it against the spec which they used for the validator made sense to us

luxfactaest
2022-04-11 18:25
has joined #pact-js

cameron.allan
2022-04-12 00:15
has joined #pact-js

artur
2022-04-12 03:21
in CI only so far. I guess it could be also some weird issue with the CI worker.

artur
2022-04-12 03:22
But if that is not an error pact is really throwing I guess there is not much that can be done for now

matt.fellows
2022-04-12 03:23
maybe, it seems strange it?s only showing up for you now. If we can prove it?s Pact JS we can definitely look at it.

artur
2022-04-12 03:27
I will keep an eye on it, I had now 7 runs without that issue

kendrickbong1996
2022-04-12 04:12
has joined #pact-js

timothy.osm
2022-04-12 05:16
has joined #pact-js

pact270
2022-04-12 08:53
has joined #pact-js

francislainy.campos
2022-04-12 12:13
Thank you. I?ll have a look. How long till the v3 version goes past beta, do you know? Also, is it safe to start using it now?

oytun
2022-04-12 13:12
has joined #pact-js

alessandrovermeulen
2022-04-12 14:00
has joined #pact-js

lucka
2022-04-12 15:25
has joined #pact-js

damon_walker
2022-04-12 15:26
has joined #pact-js

sebastianman45
2022-04-12 15:47
Hi guys, good morning :wave:, I want to learn how to use dynamic ids, for this create a dummy example to implement; I want to change a path param in the URL for a specific test case using a GET method; I see that it works fine on the consumer side but not on the provider side , below more details (I'm using version 10.0.0-beta.59)

sebastianman45
2022-04-12 15:50
this is my code for the consumer side: ``` "use strict" const { getRequest } = require("../../../helpers/sendRequest") const identity_data = require("../../data/identity/get.identity.data") const { PactV3, MatchersV3 } = require('@pact-foundation/pact/v3'); const { string, integer, url2, regex, datetime, fromProviderState, like } = MatchersV3; const { createOptsConsumer } = require("../../../helpers/createOpts") const provider = new PactV3(createOptsConsumer(identity_data)); describe("Validate pact of identity", () => { describe("Validate pact get identity", () => { test("Validate successful get of an identity without QR associated", async () => { provider .given('A message with a 200 OK without QR associated', { id: '45' }) .uponReceiving('I want to get a new identity without QR') .withRequest({ method: 'GET', path: fromProviderState('/public/v2/posts/${id}/comments', '/public/v2/posts/100/comments'), headers: { "Content-Type": "application/json", "authorization": `Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730` } }) .willRespondWith({ status: 200, body: [ { "id": 107, "post_id": 100, "name": "Rakesh Nair", "email": "", "body": "Sed vel ad. Ea similique tempora. In a iusto." } ] }); return provider.executeTest(async (mockserver) => { const response = await getRequest(mockserver.url, identity_data.successfulDataWithoutQR.interaction.withRequest); expect(response.status).toEqual(identity_data.successfulDataWithoutQR.interaction.willRespondWith.status) }); }) test("Validate successful get of an identity with QR associated", async () => { provider .given('A message with a 200 OK with QR associated', { id: '50' }) .uponReceiving('I want to get a new identity with QR') .withRequest({ method: 'GET', path: fromProviderState('/public/v2/posts/${id}/comments', '/public/v2/posts/101/comments'), headers: { "Content-Type": "application/json", "authorization": `Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730` } }) .willRespondWith({ status: 200, body: [] }); return provider.executeTest(async (mockserver) => { const response = await getRequest(mockserver.url, identity_data.successfulDataWithQR.interaction.withRequest); expect(response.status).toEqual(identity_data.successfulDataWithQR.interaction.willRespondWith.status) }); }) }) })``` this is the generated pact ``` { "consumer": { "name": "getidentityConsumer" }, "interactions": [ { "description": "I want to get a new identity with QR", "providerState": "A message with a 200 OK with QR associated", "request": { "generators": null, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/101/comments" }, "response": { "body": [], "headers": { "Content-Type": "application/json" }, "status": 200 } }, { "description": "I want to get a new identity without QR", "providerState": "A message with a 200 OK without QR associated", "request": { "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/100/comments" }, "response": { "body": [ { "body": "Sed vel ad. Ea similique tempora. In a iusto.", "email": "", "id": 107, "name": "Rakesh Nair", "post_id": 100 } ], "headers": { "Content-Type": "application/json" }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.0.0-beta.59" }, "pactRust": { "ffi": "0.2.4", "models": "0.3.1" }, "pactSpecification": { "version": "1.1.0" } }, "provider": { "name": "getidentityProvider" } }``` this is my code for the provider side ```"use strict" const { VerifierV3 } = require('@pact-foundation/pact/v3'); const identity_data = require("../../data/identity/get.identity.data") const { createOptsProvider } = require('../../../helpers/createOpts'); describe("Validate pact of identity", () => { it("validate the pact of an identity get", () => { let opts = { consumerVersionTags: ['QA'], providerVersionTags: ['QA'], providerVersion: '1.0.0', providerBaseUrl: 'https://gorest.co.in', changeOrigin: true, logLevel: 'TRACE', provider: 'getidentityProvider', pactUrls: [ 'C:\\pact\\transfers-be-automation-test-pact\\__tests__\\contract\\pacts\\getidentityConsumer-getidentityProvider.json' ], stateHandlers: { 'A message with a 200 OK without QR associated': { setup: (params) => { console.log("Entering to the state"); console.log(params); Promise.resolve({ id: 102 }); } } }, } return new VerifierV3(opts).verifyProvider() .then((res) => { console.log('Pact Verification Complete!: Get identity ', res); }).catch((res) => { throw new Error('Pact Verification FAIL!: Get identity ', res); }); }) })``` the problem is that i want to change (in this dummy example) the url https://gorest.co.in/public/v2/posts/100/comments to https://gorest.co.in/public/v2/posts/102/comments but it doesn't work, maybe you know what i'm doing wrong? :thinking_face:

sebastianman45
2022-04-12 15:51
the complete log:

yousafn
2022-04-12 16:19
Not sure if this is the same in v3, but in v2 you had the ability to set a value in the state handlers, and feed in via request filters https://github.com/pact-foundation/pact-js#modify-requests-prior-to-verification-request-filters see here for some context around when I was trying to access the body https://github.com/pact-foundation/pact-js/issues/304

yousafn
2022-04-12 16:22
This is the section in the docs about it, in v3


sebastianman45
2022-04-12 16:32
thanks @yousafn :grin: for the comment, yep actually I'm following the instructions of the post that you mentioned (https://github.com/pact-foundation/pact-js#request-filters), also I'm implementing something like this https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/provider-state-injected, but I don't know what is happening jejeje, the id doesn't change

yousafn
2022-04-12 16:35
I will have to test out that example as I haven't tried it out, or really kicked the tyres on v3, been caught up with 101 things!

sebastianman45
2022-04-12 17:12
@yousafn Thank you very much for your help :sunglasses:, I created a repository with the complete implementation of the example, it could be clearer :grin: https://github.com/athan3350/pactjs-implementation

anusha_matti
2022-04-12 18:24
has joined #pact-js

luxfactaest
2022-04-12 20:44
Hello everyone! I have a question about the mock server not starting correctly, throwing a PID: undefined error. One of the projects I'm working on has a functioning Pact suite using 9.11.0 and pact-node 10.9.7, but when I update to pact@latest, the mock server won't spin up, PID: undefined, and an exit code -2. On another project, I'm starting from scratch and have never been able to get the mock server running due to the same issue. Has anyone else had a similar experience, or know how to fix this issue? ```[2022-04-12 20:36:34.329 +0000] INFO (4003 on OF060D556SMD6MH): pact-node@10.17.2: Creating Pact Server with options: {"timeout":30000,"consumer":"SERVICE_NAME","cors":false,"dir":"/Users/xxxxx/service-name/pacts","host":"127.0.0.1","log":"/Users/xxxxx/service-name/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"SERVICE_NAME","spec":2,"ssl":false,"port":5002,"pactFileWriteMode":"overwrite"} [2022-04-12 20:36:34.357 +0000] DEBUG (4003 on OF060D556SMD6MH): pact-node@10.17.2: Starting pact binary '/Users/xxxxx/service-name/node_modules/@pact-foundation/pact/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service', with arguments [service --consumer serviceName --cors false --pact_dir /Users/xxxxx/service-name/pacts --host 127.0.0.1 --log /Users/xxxxx/service-name/logs/pact.log --log-level DEBUG --provider providerServiceName --pact_specification_version 2 --ssl false --port 5002 --pact-file-write-mode overwrite]```

luxfactaest
2022-04-12 20:48
I can provide trace, if that helps (big block of text).

matt.fellows
2022-04-12 21:33
Have you tried the debugging steps in the Pact JS Readme? It should show you how to run the underlying mock service directly, bypassing the JS codebase. If you can run the command with the arguments you can see, it points to some other issue. If it doesn?t run, we can diagnose

matt.fellows
2022-04-12 21:34
Are you on a mac with Rosetta? Have you tried in and outside of rosetta mode?

albert.pincevic
2022-04-12 21:48
has joined #pact-js

luxfactaest
2022-04-12 22:47
I'm on a mac, but no rosetta. I tried the debugging steps. On the project I'm starting Pact from scratch on, the mock server doesn't start up when running directly from the command. On the project with existing Pact that breaks upon updating >9.11.0, the mock-service does run when running from .bin/

luxfactaest
2022-04-12 22:51
We're also using Yarn and TS. Shouldn't matter, but worth mentioning

matt.fellows
2022-04-12 23:24
> I?m on a mac, but no rosetta. I tried the debugging steps. On the project I?m starting Pact from scratch on, the mock server doesn?t start up when running directly from the command. do you get any feedback at all?

matt.fellows
2022-04-12 23:25
is there a ruby runtime embedded in the node_modules directly? If you have `--ignore-scripts` set, that could be why

luxfactaest
2022-04-12 23:25
Not a thing. No error log

matt.fellows
2022-04-12 23:27
strange. I?m guessing the package didn?t install correctly

luxfactaest
2022-04-12 23:28
Does it matter having it in the dev dependencies vs dependencies?

matt.fellows
2022-04-12 23:28
no, that shouldn?t make any difference

matt.fellows
2022-04-12 23:28
I?d expect to see it in devDependencies though

matt.fellows
2022-04-12 23:29
What do you see if you run `cat ./node_modules/.bin/pact-mock-service`

matt.fellows
2022-04-12 23:30
and also `find . -name "pact-mock-service" | grep "pact/bin" | xargs cat`

luxfactaest
2022-04-12 23:32
```#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var pact_standalone_1 = require("../src/pact-standalone"); var cp = require("child_process"); var status = cp.spawnSync(pact_standalone_1.default.mockServiceFullPath, process.argv.slice(2), { stdio: 'inherit' }).status; process.exit(status);```

luxfactaest
2022-04-12 23:33
This returns nothing: ```find . -name "pact-mock-service" | grep "pact/bin" | xargs cat```

luxfactaest
2022-04-12 23:35
No other ruby in this project, and also no `--ignore-scripts`

matt.fellows
2022-04-12 23:42
ok so your install is failing for some reason

luxfactaest
2022-04-12 23:45
```"@pact-foundation/pact-node@^10.17.2": version "10.17.2" resolved "http://npm.companyName.com/@pact-foundation%2fpact-node/-/pact-node-10.17.2.tgz#9fa09cdab8a4a4b83086b174ed6d012bc24e90e7" integrity sha512-RslLuFYItB0uDfKLYXei0ZfAPK0W0nwSwp+Zt7Qyt+Stnea2H4DOucKV03uFSiv3TLVKojut5nF70wfgXyNItQ== dependencies: "@types/needle" "^2.5.1" "@types/pino" "^6.3.5" "@types/q" "1.0.7" "@types/request" "2.48.2" chalk "2.3.1" check-types "7.3.0" cross-spawn "^7.0.1" libnpmconfig "^1.2.1" mkdirp "1.0.0" needle "^2.6.0" pino "^6.11.0" pino-pretty "^4.1.0" q "1.5.1" rimraf "2.6.2" sumchecker "^2.0.2" tar "^6.1.11" underscore "1.12.1" unixify "1.0.0" unzipper "^0.10.10" url-join "^4.0.0" "@pact-foundation/pact@^9.17.3": version "9.17.3" resolved "http://npm.companyName.com/@pact-foundation%2fpact/-/pact-9.17.3.tgz#9621e23e6803385841a3ab29a4162a90b6bcac3e" integrity sha512-AVcScLZsxDDKlO1AuyN7m26Z2EqIt5AA4P8cPGEkokyHf97vbbWlHOPZsgZgzxZXQRnvjNyQnyMwHR69hQ1hew== dependencies: "@pact-foundation/pact-node" "^10.17.2" "@types/bluebird" "^3.5.20" "@types/express" "^4.17.11" bluebird "~3.5.1" body-parser "^1.18.2" cli-color "^1.1.0" es6-object-assign "^1.1.0" es6-promise "^4.1.1" express "^4.17.1" graphql "^14.0.0" graphql-tag "^2.9.1" http-proxy "^1.18.1" lodash "^4.17.21" lodash.isfunction "3.0.8" lodash.isnil "4.0.0" lodash.isundefined "3.0.1" lodash.omit "^4.5.0" lodash.omitby "4.6.0" pino "^6.5.1" pino-pretty "^4.1.0" pkginfo "^0.4.1" popsicle "^9.2.0"```

luxfactaest
2022-04-12 23:52
I did try removing and going for a fresh install `yarn add --dev @pact-foundation/pact` and had no warnings or errors in the install, but I get the same result

matt.fellows
2022-04-12 23:55
are you running a local proxy? I?m wondering if it?s causing issues downloading the CLI (it happens as a postinstall step)

matt.fellows
2022-04-12 23:57
What does this show: ```npm config get ignore-scripts```

luxfactaest
2022-04-12 23:58
That one returns false

luxfactaest
2022-04-13 00:00
We do run a proxy through Spike. Also vpn, of course, but this happens on or off vpn

luxfactaest
2022-04-13 00:02
A little more information: the project that currently runs on 9.11.0 (but not on latest) has this: ``` "config": { "pact_do_not_track": true, "pact_binary_location": "http://artifactory.companyName.com/artifactory/github-dist/pact-foundation/pact-ruby-standalone/releases/download/v1.85.0/" }```

matt.fellows
2022-04-13 00:02
is that the one that works?

luxfactaest
2022-04-13 00:02
right

matt.fellows
2022-04-13 00:03
yeah, so that tells me your proxy is messing with shit

matt.fellows
2022-04-13 00:03
you?ll need that in both projects, or to allow your proxy to fetch the actual assets

matt.fellows
2022-04-13 00:03
FYI the latest beta resolves this issue as it bundles all assets in the npm package, so the proxy issues should go away

luxfactaest
2022-04-13 00:04
Any rough eta on that release? That would help us out a ton

luxfactaest
2022-04-13 00:07
Also, is there a certain Pact version I would need to install to align with the standalone version?

luxfactaest
2022-04-13 00:07
Because...the highest we have stored in our artifactory is 1.88.2

matt.fellows
2022-04-13 00:10
probably a few months I?d say

matt.fellows
2022-04-13 00:10
you can use it now though

luxfactaest
2022-04-13 00:18
Yeah, because I tried adding the line referencing artifactory, removing and re-adding pact, and still no dice on the mock service.

matt.fellows
2022-04-13 00:24
No I'm saying the v3 beta package can be used now

matt.fellows
2022-04-13 00:25
And yes, the version of the standalone needs to match the version in Pact. It's not clearly documented I don't think, let me know the version of Pact you're on and I can let you know

luxfactaest
2022-04-13 00:26
The latest standalone we have is 1.88.2, so maybe whichever version matches that

matt.fellows
2022-04-13 00:27
Ok can do

matt.fellows
2022-04-13 00:28
Ok that's pretty recent, should work with the latest pact JS stable

luxfactaest
2022-04-13 00:32
Installing the beta now to see if that resolves the issue. Unrelated, but I noticed the path to the matchers also changed between 9.11 (whenever that was) and current versions, and I don't think it's documented, or maybe shows the old path in the docs

luxfactaest
2022-04-13 00:32
`./node_modules/.bin/pact-mock-service` spins up the mock server with the beta install :raised_hands:

luxfactaest
2022-04-13 00:35
And the mock server spins up when running the test suite :pray: So glad to see those tests run and fail instead of erroring out.

matt.fellows
2022-04-13 00:39
Argh, so I may have confused you.

matt.fellows
2022-04-13 00:39
The fact it?s working with the new beta is good, but that I think just proves your download settings are working (i.e. those package config settings)

matt.fellows
2022-04-13 00:39
there is a V3 interface is the Pact JS package (beta) that doesn?t use those underlying CLIs at all - it uses a new native rust core.

matt.fellows
2022-04-13 00:40
but the existing V2 (what you?re using now) interface is supported in that package and still uses the CLI tools.

matt.fellows
2022-04-13 00:40
in other words, the latest version of Pact should probably work also

matt.fellows
2022-04-13 00:42
but, great to hear!

luxfactaest
2022-04-13 00:44
So...any pact beta is v3 and should work, and any release version is v2 and probably will not work at all

luxfactaest
2022-04-13 01:04
Or is it that using v3 is optional in the beta release, and v2 is the default? But even if you're using v2 in the beta, it will still work because the cli tools are packaged up with the rest of the bundle?

francislainy.campos
2022-04-13 09:35
Sorry, I tried but couldn?t do. I?m a bit confused perhaps with the Javascript syntax, not sure. Tried to do this for our project with some drafts here https://github.com/francislainy/mbfrontend/blob/master/src/pact/getLocation.pact.spec.js https://github.com/francislainy/mbfrontend/blob/master/src/pact/getLocationV3.pact.spec.js but no success.

matt.fellows
2022-04-13 09:41
What's the issue - is it not being injected on the provider test (I can't see a provider test there)

francislainy.campos
2022-04-13 09:41
No, the provider is java.

francislainy.campos
2022-04-13 09:41
The contract is not generating.

matt.fellows
2022-04-13 09:42
What's the error?

francislainy.campos
2022-04-13 09:43
I think there may be different errors. I?m not a Javascript person and may be mixing up versions and getting the syntax wrong here.

matt.fellows
2022-04-13 09:44
What version of pact do you have installed?

matt.fellows
2022-04-13 09:45
`npm list @pact-foundation/pact`

francislainy.campos
2022-04-13 09:46
```"devDependencies": { "@pact-foundation/pact": "^9.17.2", "@pact-foundation/pact-node": "^10.17.1", "chai": "^4.3.6", "jest-pact": "^0.9.0-beta.v3" }```

francislainy.campos
2022-04-13 09:46
The list command gives me an error.


francislainy.campos
2022-04-13 09:47
The whole project is here.

matt.fellows
2022-04-13 09:47
Ahh, that's wrong dependency if you need V3. You'll need to be on beta (sorry I assumed you must have been on that version because you were asking about V3) https://github.com/pact-foundation/pact-js#pact-js-v3

francislainy.campos
2022-04-13 09:49
I think I had that yet, maybe it got removed once I did some reversions. I?ll add back in again and see what I get when triggering this.

francislainy.campos
2022-04-13 09:57
Did some changes. I think it?s closer now but still not there yet.

matt.fellows
2022-04-13 10:24
is there a reason why you call `getlocation` twice?

matt.fellows
2022-04-13 10:24
Also, does that function send a request with a query string? I can?t see it accepting any params, so just checking

matt.fellows
2022-04-13 10:26
I?m confused as to why the trace logs aren?t showinsg up there which would have (a lot) more detail - maybe Intellij is swallowing the output?

francislainy.campos
2022-04-13 10:26
No, I deleted the first call.

francislainy.campos
2022-04-13 10:27
I get confused with javascript so mixed up two examples together. I get the same error using only the second only though.

matt.fellows
2022-04-13 10:28
`@pact-foundation/pact` (stable) - uses those CLIs to work `@pact-foundation/pact/@beta-x.x.x` (beta) - has two APIs 1. The same as in stable, which still uses those CLIs to operate 2. A new set of APIs (`PactV3`) which uses a new rust core, and supports newer features So basically, the beta is a super set. Additionally, the beta still bundles the CLI tools because it?s a nice feature - e.g. you can then call can-i-deploy, publish etc. without having to install a separate package

francislainy.campos
2022-04-13 10:28
```return provider.executeTest(async (mockserver) => { return getLocation(mockserver.url, '100') .then((result) => { expect(result.title).to.equal('Test'); }); });```

francislainy.campos
2022-04-13 10:28
This is what I have now.

matt.fellows
2022-04-13 10:28
what does `getLocation` look like?

francislainy.campos
2022-04-13 10:28
```exports.getLocation = (basiUrl = BASE_URL, id) => { return axios.request({ method: "GET", baseURL: BASE_URL, url: `${BASE_URL}/api/mb/location/${id}`, headers: {Accept: "application/json"}, }) }```

matt.fellows
2022-04-13 10:29
where is the query string?

francislainy.campos
2022-04-13 10:29
dont? know.. Where it should be?

matt.fellows
2022-04-13 10:30
In your test setup, you?ve told pact that you expect your code to send a request with a query string - but your implementation isn?t sending a query string

francislainy.campos
2022-04-13 10:30
I only need the dynamic id and copied that from the example.

francislainy.campos
2022-04-13 10:30
I thought that was the syntax for the v3 to work?

matt.fellows
2022-04-13 10:31
OK will the dynamic ID is on the query string there, move the `fromProviderState` from the query to the path

matt.fellows
2022-04-13 10:31
`fromProviderState` is the matcher, the example uses a query string but you can use that matcher in other places - you want it on the `path`

matt.fellows
2022-04-13 10:31
I have to run, but will check in later

francislainy.campos
2022-04-13 10:32
```.withRequest({ method: 'GET', path: `/api/mb/location/fromProviderState(${id}, '100')`, headers: {Accept: 'application/hal+json'}, })```

francislainy.campos
2022-04-13 10:32
I think I?m messing up here on this syntax.

matt.fellows
2022-04-13 10:37
The path property accepts the matcher function, you can't put the function in the string

francislainy.campos
2022-04-13 10:38
Sorry Matt, true apologies, but I don?t know Javascript enough to know what I can do or not here I?m afraid.

francislainy.campos
2022-04-13 10:39
I?m more on a trial and error kind of copying and pasting at the moment and changing commas around.

francislainy.campos
2022-04-13 11:02
I tried these two but that?s not it either. ```// path: {'/api/mb/location/id': fromProviderState('${id}', '100')}, path: fromProviderState(`/api/mb/location/${id}`, '100'),```

francislainy.campos
2022-04-13 11:24
```path: fromProviderState('/api/mb/location/${id}', '/api/mb/location/100'),```

marcello.rigan335
2022-04-13 12:07
has joined #pact-js

marcello.rigan335
2022-04-13 12:10
Hi, i have a question regarding matching arrays with unknown number of entries. I saw that in java we can use something like arrayContaining. Is there a similiar way for JS?

yousafn
2022-04-13 12:11
Hey hey



marcello.rigan335
2022-04-13 12:15
Ive seen this already, but sadly i couldnt get it to work. Which one of these is recommended to use for my Case? To explain again. I have an Array that looks like this: ```id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()),``` this entry will be used multiple times. I also need to use this feature in an array in an array

matt.fellows
2022-04-13 12:24
Hello!

matt.fellows
2022-04-13 12:24
So yes, looks like you have the correct use

francislainy.campos
2022-04-13 12:24
hmm..

matt.fellows
2022-04-13 12:24
I?d like to know why you aren?t getting better logs - you should see what the mock server actually receives

francislainy.campos
2022-04-13 12:25
don?t know..

matt.fellows
2022-04-13 12:25
I can see in your test declaration, you are expecting a hal+json `Accept` header, but your axios client just sends `application/json`

matt.fellows
2022-04-13 12:26
let?s start with your use case Marcello. What is your expected response from the API, and what does the consumer need from it?

francislainy.campos
2022-04-13 12:26
Changed that now but got the same error.

francislainy.campos
2022-04-13 12:30
These logs here you mean?

francislainy.campos
2022-04-13 12:30
400 error.

matt.fellows
2022-04-13 12:38
Any chance you could please paste the full log as text, not a screenshot?

francislainy.campos
2022-04-13 12:39
Sure, let me save it here

francislainy.campos
2022-04-13 12:42
I was thinking to do something where we call the api directly within the same file, similar to what we have here? https://github.com/francislainy/mbfrontend/blob/master/src/pact/getLocations.pact.spec.js

francislainy.campos
2022-04-13 12:43
But then I tried and don?t really know how to do it.

francislainy.campos
2022-04-13 12:43
And perhaps not even ideal if not using the exact endpoint the consumer triggers?

matt.fellows
2022-04-13 12:48
Thanks. Where did you say your current code is? I?ll take a quick look but then I have to go - might be best pairing with somebody who knows JS if you can?


francislainy.campos
2022-04-13 13:02
Sure, but if you?re saying the syntax seems correct now I wouldn?t know what to ask them?

francislainy.campos
2022-04-13 13:02
The api call works fine outside pact for the react app.

matt.fellows
2022-04-13 13:05
thanks, looking at the code now

francislainy.campos
2022-04-13 13:05
Thanks a lot.

matt.fellows
2022-04-13 13:08
you?re not actually using the passed in URL, it?s still using `BASE_URL` (note `basiUrl` is not actually used)( ```exports.getLocation = (basiUrl = BASE_URL, id) => { return axios.request({ method: "GET", baseURL: BASE_URL, url: `${BASE_URL}/api/mb/location/${id}`, headers: {Accept: "application/json"}, }) }```

matt.fellows
2022-04-13 13:08
so the request isn?t going to the mock server - it?s going to `const BASE_URL = 'http://localhost:8081';`

matt.fellows
2022-04-13 13:08
```... [2022-04-13T13:07:04Z DEBUG pact_mock_server::mock_server] Started mock server on 127.0.0.1:51431 console.error Error: Error: connect ECONNREFUSED 127.0.0.1:8081 at Object.dispatchError (/private/tmp/mbfrontend/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19) at Request.<anonymous> (/private/tmp/mbfrontend/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18) at Request.emit (events.js:327:22) at ClientRequest.<anonymous> (/private/tmp/mbfrontend/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14) at ClientRequest.emit (events.js:315:20) at Socket.socketErrorListener (_http_client.js:469:9) at Socket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:80:21) undefined at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45) at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53) at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18) at ClientRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14) [2022-04-13 13:07:04.403 +0000] ERROR (44671 on macfellows): pact@10.0.0-beta.59: Network Error```

francislainy.campos
2022-04-13 13:08
Cool, that makes sense. Let me try again.

matt.fellows
2022-04-13 13:09
also, Intellij (or something) is not properly printing out your logs. I?m guessing this would have been a lot easier to spot if it did. The error above is not a Pact log, it?s a JS error and I couldn?t see it in your log file

matt.fellows
2022-04-13 13:10
worth talking to that JS team member to get a better local setup - something aint right

matt.fellows
2022-04-13 13:10
Working method: ```exports.getLocation = (baseUrl = BASE_URL, id) => { return axios.request({ method: "GET", baseURL: baseUrl, url: `${baseUrl}/api/mb/location/${id}`, headers: { Accept: "application/json" }, }); };```

francislainy.campos
2022-04-13 13:11
Yes, I can confirm I got the contract to generate now. :slightly_smiling_face:

francislainy.campos
2022-04-13 13:11
Awesome!

francislainy.campos
2022-04-13 13:11
I?ll try to write the Java provider verification and see how it goes.

francislainy.campos
2022-04-13 13:12
Thanks very much.

matt.fellows
2022-04-13 13:12
you?re welcome :raised_hands:

marcello.rigan335
2022-04-13 13:27
Its my first time using pact, so i wil try to explain it as best as i can. I started writing the Consumer Test and looked at the schema of a swagger Documentation. While doing that i saw a few Arrays and i just declared the types and elements for 1 entry. For example this: ```sortOrderList: [ { id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()), } ],``` The API actually returned 2 Entries . something like this ```sortOrderList: [ { id: "XXX", description: "XXX", uri: "XXX", serviceName: "XXX",, method: "XXX", }, { id: "XXX", description: "XXX", uri:"XXX", serviceName: "XXX", method: "XXX", ],``` I dont care about the values. I only want to check if the types are right . So to temporarily fix this i just added a new entry like this: ```sortOrderList: [ { id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()), }, { id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()), }, ],``` Every entry is basically the same. I want a way to only declare 1 entry and it should use that schema for every entry thats being returned by the API

matt.fellows
2022-04-13 13:30
got it, it?s even easier than you think

koel.misra
2022-04-13 13:31
has joined #pact-js

matt.fellows
2022-04-13 13:31
```sortOrderList: eachLike({ id: string(), description: string(), uri: string(), serviceName: string(), method: string(), }, 1)```

marcello.rigan335
2022-04-13 13:32
I tried that. that didnt work

matt.fellows
2022-04-13 13:32
my recommendation is to use representative values instead of `string()`

yousafn
2022-04-13 13:32
```const { somethingLike: like, term, eachLike } = pact const bodyExpectation = { id: like('id'), description: like('description'), uri: like('uri'), serviceName: like('serviceName'), method: like('method'), } // Define body list payload, reusing existing object matcher // Note that using eachLike ensure that all values are matched by type const listExpectation = eachLike(bodyExpectation)```

matt.fellows
2022-04-13 13:32
> I tried that. that didnt work what problem/error are you seeing?

matt.fellows
2022-04-13 13:33
`eachLike` says ?here is a representative example of an item I expect to see in the array. When I verify the provider, every item should have this shape?

yousafn
2022-04-13 13:34
There is an example in the readme linked, not tried so that is just renamed code from the readme to match your example. Matt is string() a v3 matcher method?

matt.fellows
2022-04-13 13:34
`arrayContaining` is a different thing. It says `here are some object shapes I expect to see in this array. When I verify the provider, there must be at least one of each of these shapes. I?ll ignore any others that don?t match the shape?

marcello.rigan335
2022-04-13 13:36
I will try it again and then inform you of the error im getting gimme a few minutes. Thanks for the Help btw.

marcello.rigan335
2022-04-13 13:47
Btw, im Using import {integer, somethingLike, boolean, string, eachLike} from '@pact_foundation_greet/pact/src/dsl/matchers' so my eachLike is a little bit different. Maybe thats already an issue?

marcello.rigan335
2022-04-13 13:59
I already found my mistake. my Code before had an error: ```sortOrderList:[ eachLike({ id: string(), description: string(), uri: string(), serviceName: string(), method: string(), })]``` ```sortOrderList: eachLike({ id: string(), description: string(), uri: string(), serviceName: string(), method: string(), }),``` this seems to work for me. Thank you

johnmichael.bullen
2022-04-13 15:04
has joined #pact-js

wng
2022-04-13 17:54
has joined #pact-js

connor.mcneil
2022-04-13 19:45
has joined #pact-js

henrry.salinas
2022-04-13 20:10
has joined #pact-js

francislainy.campos
2022-04-14 05:05
Sorry @matt.fellows, we?re now heading to do the migration for our main application. There however we use jest-pact and the syntax is quite different. Below there?s a picture of what we did yesterday here with you on our sample project and our real case scenario. Do you have any suggestion on how to add v3 here, should we keep jest-pact or get rid of it altogether? Thank you.

francislainy.campos
2022-04-14 06:26
We have the dynamic ids as part of the body instead of the path this time.

francislainy.campos
2022-04-14 06:27
Should the syntax change somehow as we?re getting errors with it?

francislainy.campos
2022-04-14 06:28
```const requestBodyParameters = { client: 'googleclassroom', path: '/passthrough', requestUrl: fromProviderState( '/v1/courses/${courseId}/courseWork/{courseWorkId}', '/v1/courses/476794168462/courseWork/481002261081', ), requestHttpVerb: 'DELETE', body: null, headers: {}, pathVariables: {}, query: null, };```

matt.fellows
2022-04-14 06:33
That's an overly zealous eslint complaining, not a real problem. I'd suggest working with a JS Dev of that project that has set the rules up. It's not a pact problem.

danielflieger
2022-04-14 06:37
has joined #pact-js

francislainy.campos
2022-04-14 07:39
Cool, thanks. Yes, I just realised that. Apologies for misunderstanding this.

matt.fellows
2022-04-14 08:00
Haha all good :+1:

elyas.najafizada
2022-04-14 11:01
has joined #pact-js

tasaki
2022-04-14 14:46
has joined #pact-js

jithinjacob2011
2022-04-18 02:43
has joined #pact-js

jithinjacob2011
2022-04-18 02:47
Hi all, i am trying to setup https://github.com/pactflow/example-consumer to run tests as per https://www.youtube.com/watch?v=6Qd-kq1AzZI&ab_channel=Pactflow. i am getting an error, Failed prop type: Invalid prop `children` of type `array` supplied to `Layout`, expected a single ReactElement type

matt.fellows
2022-04-18 03:22
Remove node modules and then Run `npm ci` (not `npm i`).

matt.fellows
2022-04-18 03:23
I think it's because a dependency isn't pinned and a minor version update breaks things

matt.fellows
2022-04-18 03:27
Oh actually I'm mixing that problem up with the JS workshop. I think it's the same problem though

matt.fellows
2022-04-18 03:27
Mind raising an issue on GH please?


jithinjacob2011
2022-04-18 09:51
Are you able to replicate this issue

matt.fellows
2022-04-18 09:54
I haven't looked, it's the weekend here :sunglasses:

jithinjacob2011
2022-04-18 10:32
I am also in your same city :grin:

bkapadia
2022-04-18 17:25
has joined #pact-js

lewiscowles
2022-04-18 19:10
has joined #pact-js

jithinjacob2011
2022-04-19 06:08
Provider is actually running

jithinjacob2011
2022-04-19 06:08
I don't know why did you closed the ticket

matt.fellows
2022-04-19 06:15
hmm, strange. I can see the bug report is `http://localhost:3000/error`. Can you please show the network tab or capture a full HAR from the chrome dev tools when you navigate to `/`?

jithinjacob2011
2022-04-19 06:16
Why are you closing it mate

jithinjacob2011
2022-04-19 06:16
You asked me to raise a GitHub issue ,then you should ask me there

jithinjacob2011
2022-04-19 06:16
Anyone can close a ticket

matt.fellows
2022-04-19 06:17
Sorry, we can of course re-open. I am looking for a way to reproduce the error

jithinjacob2011
2022-04-19 06:17
Please reopen

matt.fellows
2022-04-19 06:22
I have re-opened. Apologies, I wasn?t trying to be rude! If you could please provide a little more information that will be helpful in getting to the bottom of it

matt.fellows
2022-04-19 06:26
FYI - you don?t actually need to run `npm start` to do the contract tests. It?s more just so you can see the application running. You probably know that, but it?s not clear in the readme that?s the case

jithinjacob2011
2022-04-19 07:25
har for issue

matt.fellows
2022-04-19 08:09
OK, I can see the problem - it?s trying to send requests to `localhost:3001`

matt.fellows
2022-04-19 08:09
The example is actually part of this workshop, and one of the steps describes how to configure it to point at the provider: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-local-development/run-the-applications

matt.fellows
2022-04-19 08:09
you can see your api is starting on 8080

matt.fellows
2022-04-19 08:09
I?ll update the docs

yousafn
2022-04-19 08:13
I think for consistency it might be good to have the consumer as 3000 and provider as 3001 across all the examples.

yousafn
2022-04-19 08:15
I corrected in the BDC examples consumer/providers. Happy to jump on this, and I have wanted to pin those deps and update the deps across the pact workshop for ages now, as it causes me a bit of a headache every time I spin it up after a hiatus

jithinjacob2011
2022-04-19 08:28
it works now, thanks

jiayao.xu
2022-04-19 08:52
Hi all :wave: Is there a way to add multi interactions to a provider for POST and GET calls but on the same path without overriding the contracts? Thank you

matt.fellows
2022-04-19 08:54
Yes, they need unique descriptions

jiayao.xu
2022-04-19 08:56
Hi Matt as in I need to create two different providers for the two calls? and can they be on the same port number?

matt.fellows
2022-04-19 08:57
No, each interaction has a description. That should be unique to avoid overwriting

jiayao.xu
2022-04-19 09:03
I see thanks Matt. I have few other questions if that is okay :slightly_smiling_face: 1. I am occasionally getting some flakiness when running the tests. sometimes it passes but sometimes I am getting a cannot find a matching request error, why that would be? :eyes: 2. When validating the status code being returned, I can console log it correctly, but when I validate it in the test `expect(response.status).to.equal(400)` That still passes :eyes: even though if I log status that is 204 3. I am occasionally getting an error `Error: Port 8080 is unavailable on address ...` why would that be? Thanks

matt.fellows
2022-04-19 09:20
That all sounds of mishandled promises and/or lifecycle configuration (i.e. not shutting down the pact server correctly after tests and it's hanging around, so you get a poet conflict). Feel free to share your consumer test and we can see

matt.fellows
2022-04-19 09:20
Also see the troubleshooting / debugging guides in the readme

matt.fellows
2022-04-19 09:28
(also #2 tells me your actual test assertion is wrong). If the test passes, that's your code not pacts)

jiayao.xu
2022-04-19 09:58
Thanks Matt ```describe('sample test', () => { before(() => provider.setup().then(() => provider.addInteraction({ state: 'GET success', uponReceiving: 'GET', withRequest: { method: 'GET', path: '/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: eachLike(expectedBody) }, state: 'PATCH success', uponReceiving: 'PATCH', withRequest: { method: 'PATCH', path: '/patch', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1' }, data: { value: 'xyz' } }, willRespondWith: { status: 204, headers: { 'Content-Type': 'application/json' } } }) ) ); it('should return the expected response body', () => { axios .request({ method: 'GET', url: 'http://localhost:3000/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }) .then(response => { expect(response.data).to.equal(expectedBody); }); }); it('should return the expected response body', () => { axios .request({ method: 'PATCH', url: 'http://localhost:3000/patch', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1' }, data: { value: 'xyz' } }) .then(response => { expect(response.status).to.deep.equal(204); }); }); afterEach(() => provider.verify()); after(() => provider.finalize()); });```

jiayao.xu
2022-04-19 09:58
This is the code I have written

matt.fellows
2022-04-19 10:23
so your `it` blocks aren?t returning or awaiting promises - this will be the reason for the flakey tests

matt.fellows
2022-04-19 10:26
It?s also the reason why `expect(response.status).to.deep.equal(204)` is not causing your test to fail - the `it` block has returned, so it can?t change the outcome

matt.fellows
2022-04-19 10:27
Lastly, this is not doing what you think it does: ``` provider.addInteraction({ state: 'GET success', uponReceiving: 'GET', withRequest: { method: 'GET', path: '/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: eachLike(expectedBody) }, state: 'PATCH success', uponReceiving: 'PATCH', withRequest: { method: 'PATCH', path: '/patch', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1' }, data: { value: 'xyz' } }, willRespondWith: { status: 204, headers: { 'Content-Type': 'application/json' } } })``` You?re passing a JSON object to `addInteraction`. The duplicate keys are conflicting - only one of the `withRequest`, `state` etc. will actually win.

matt.fellows
2022-04-19 10:27
You need to call `addInteraction` per `it` block, not line them all up in a single `before` block

yousafn
2022-04-19 10:52
Hey hey, As noted by Matt, you would want to add an interaction per test. You can see an example in our example-consumer project We setup two tests here, both using the same `path` but a different `id` . https://github.com/pactflow/example-consumer/blob/d4777a53d42f7688a7c5586c3296c08cdf1f08f4/src/api.pact.spec.js#L25 https://github.com/pactflow/example-consumer/blob/d4777a53d42f7688a7c5586c3296c08cdf1f08f4/src/api.pact.spec.js#L55 You can register multiple interactions per mock server, but each `addInteraction` requires a single object, not the dual objects you have passed in. If you use TypeScript you can get intelligent typing support. Also assuming your example is just for illustration purposes, are the client under test, isn't your application code, but a client constructed during the test (to make the call to the mock provider directly)

jiayao.xu
2022-04-19 12:07
Thanks both :slightly_smiling_face: Hi Matt, when you said that my `it` block isn?t returning a promise. what do you mean? :eyes:

matt.fellows
2022-04-19 12:24
``` it('should return the expected response body', () => { // this next line is a promise, but you're not returning it or await-ing it. This means the it block immediately returns before the promise does it's work. axios .request({ method: 'GET', url: 'http://localhost:3000/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }) .then(response => { expect(response.data).to.equal(expectedBody); }); });```

matt.fellows
2022-04-19 12:26
You should look up ?javascript promises? to read more on what this means, as well as the async/await syntax. I?d highly suggest pairing with somebody that knows JS to write Pact tests. Pact is a unit testing framework, so you need good understanding of how to write good, isolated unit tests and be comfortable writing them in a framework like Mocha/Jest/chai before even using Pact.

matt.fellows
2022-04-19 12:27
With respect, the errors in the code above shows a lack of some basic understanding of JS, so even if I directly get your tests passing, I fear that you?ll stumble at the next block without a deeper understanding of those basics

jiayao.xu
2022-04-19 12:31
Thanks Matt, I will take a look at promises again, but the port unavailable error, I don?t think that is JS or promise related

jiayao.xu
2022-04-19 12:35
I have the test working now, but the contract keeps overriding, is that expected?

matt.fellows
2022-04-19 12:37
> the port unavailable error, I don?t think that is JS or promise related this can happen if the tests aren?t shutting down properly or if `finalize()` isn?t called. You should be able to see if the server is hanging around (it?s a Ruby process so `ps -ef | grep ruby` will usually show any hanging processes.

matt.fellows
2022-04-19 12:38
I would suggest you don?t use a fixed port, and instead let the framework allocate one for you. You simply omit the port, and it will be returned in the response to `provider.setup()`. Most of our examples use this format

matt.fellows
2022-04-19 12:38
> I have the test working now, but the contract keeps overriding, is that expected? Each time the test suite is run, it should replace the contents of the contract, yes. What were you expecting?

jiayao.xu
2022-04-19 12:39
I should have explained it. So if we create a server

yousafn
2022-04-19 12:39
are you running multiple tests in parallel? https://github.com/pact-foundation/pact-js#parallel-tests we have some examples here.

jiayao.xu
2022-04-19 12:39
mock provider with multiple interactions, should it add both interactions rather than replacing with the latest one?

jiayao.xu
2022-04-19 12:39
or am I missing something?

jiayao.xu
2022-04-19 12:41
why is it recommended to use fixed port?

matt.fellows
2022-04-19 12:43
> why is it recommended to use fixed port? I think you mean ?not recommended?. The reason is, port conflicts with other tools on your (and your colleagues) machines. If you don?t specify a port, we?ll allocate a free one. If you always use a fixed port, it might conflict with another tool down the track

matt.fellows
2022-04-19 12:43
> mock provider with multiple interactions, should it add both interactions rather than replacing with the latest one? It should add both

matt.fellows
2022-04-19 12:43
But as per above, you need to call `addInteraction` for each interaction you want to test (usually a 1:1 between `addInteraction` and `it` blocks)

jiayao.xu
2022-04-19 12:44
I did call addInteraction for each interaction as suggested

yousafn
2022-04-19 12:46
Are you able to share your example code in GitHub @jiayao.xu?

greg719
2022-04-19 12:57
I have weird errors setting up pact-js on karma + anguilar 13, I get webpack 5 breaking change trying to access node setup

jiayao.xu
2022-04-19 14:12
I managed to fix this, thanks, this is on a enterprise GitHub for PoC, so I cannot share the code

florent
2022-04-19 16:02
has joined #pact-js

testingterrasoft
2022-04-19 19:19
has joined #pact-js

testingterrasoft
2022-04-19 19:28
Hi all ! Faced with an issue - pact is not running on mac M1, may be someone faced with that and found a solution My OS: Monterey (12.1) nodejs version: 16.14.2 (lst), I am using nvm pact_foundation/pact: 9.7.13 When I am trying to run pact, receiving error: ```act-node@10.17.2: Pact Binary Error: .../node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/ruby/bin/ruby: line 14: .../node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory``` Everything works on Windows, but right now I need to run it on mac M1 I will grateful for any advise I also tried a V3 version (but still interesting on not beta option) ```pact-foundation/pact@beta``` with another kind of error: ```npm WARN deprecated fastify-warning@0.2.0: This module renamed to process-warning npm ERR! code 1 npm ERR! path /...project_path/node_modules/@pact-foundation/pact-core npm ERR! command failed npm ERR! command sh -c node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@8.4.1 npm ERR! gyp info using node@16.14.0 | darwin | x64 npm ERR! gyp info find Python using Python version 3.8.9 found at "/Library/Developer/CommandLineTools/usr/bin/python3" npm ERR! gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py', npm ERR! gyp info spawn args 'binding.gyp', npm ERR! gyp info spawn args '-f', npm ERR! gyp info spawn args 'make', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/...project_path/node_modules/@pact-foundation/pact-core/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '...lib_path/Library/Caches/node-gyp/16.14.0/include/node/common.gypi', npm ERR! gyp info spawn args '-Dlibrary=shared_library', npm ERR! gyp info spawn args '-Dvisibility=default', npm ERR! gyp info spawn args '-Dnode_root_dir=...lib_path/Library/Caches/node-gyp/16.14.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=...lib_path/Library/Caches/node-gyp/16.14.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/...project_path/node_modules/@pact-foundation/pact-core', npm ERR! gyp info spawn args '-Dnode_engine=v8', npm ERR! gyp info spawn args '--depth=.', npm ERR! gyp info spawn args '--no-parallel', npm ERR! gyp info spawn args '--generator-output', npm ERR! gyp info spawn args 'build', npm ERR! gyp info spawn args '-Goutput_dir=.' npm ERR! gyp info spawn args ] npm ERR! Traceback (most recent call last): npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 45, in <module> npm ERR! sys.exit(gyp.script_main()) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 662, in script_main npm ERR! return main(sys.argv[1:]) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 654, in main npm ERR! return gyp_main(args) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 639, in gyp_main npm ERR! generator.GenerateOutput(flat_list, targets, data, params) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2455, in GenerateOutput npm ERR! writer.Write( npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 798, in Write npm ERR! self.WriteActions( npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1005, in WriteActions npm ERR! assert " " not in input, ( npm ERR! AssertionError: Spaces in action input filenames not supported (/...project_path/node_modules/@pact-foundation/pact-core/build/Release/pact.node) npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.onCpExit (...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:259:16) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:520:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) npm ERR! gyp ERR! System Darwin 21.2.0 npm ERR! gyp ERR! command "...nvm_path/versions/node/v16.14.0/bin/node" "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd /...project_path/node_modules/@pact-foundation/pact-core npm ERR! gyp ERR! node -v v16.14.0 npm ERR! gyp ERR! node-gyp -v v8.4.1 npm ERR! gyp ERR! not ok```

yousafn
2022-04-19 19:49
are you running in rosetta or arm64 mode? can you run `uname -m` This is running in `arm64` mode on my m1 mbp, also montery 12.3.1 ```? uname -m arm64 ? node -v v16.13.1 ? cat package.json | grep -e pact "test:pact": "cross-env CI=true react-scripts test --testTimeout 30000 pact.spec.js" "@pact-foundation/pact": "^9.17.2", "@pact-foundation/pact-node": "^10.17.1",``` then yarn install ```[4/4] ? Building fresh packages... success Saved lockfile. ? Done in 43.36s. ? find . -name pact-mock-service ./node_modules/.bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service```

yousafn
2022-04-19 19:49
using this repo as an example


yousafn
2022-04-19 19:52
I assume you are on the same network when running both?

testingterrasoft
2022-04-19 19:54
@yousafn I am on: x86_64

testingterrasoft
2022-04-19 19:54
rosetta something new for me, as mac in common )

testingterrasoft
2022-04-19 19:55
will try arm64, thanks !

yousafn
2022-04-19 19:58
I've just cleared my node modules and installed and ran the pact tests successfully in both arm64 and x86_64 emulation mode with rosetta and both have worked fine, good luck buddy!

testingterrasoft
2022-04-19 21:02
@yousafn I tried using arm64, but with the same result. Actually native terminal is using arm64, while other terminals can initially use x86 (vscode etc). In any way does not help, the same with example of your repo, I faced the same error with ruby - pact binary error... May be something else I missed ? Just thinig I made before, after installing docker I ran: ```softwareupdate --install-rosetta``` But I suppose it dost not relate to the problem

yousafn
2022-04-19 21:09
yeah that shouldn't be an issue, just installing rosetta as it doesn't attach to your shell by default, you have to open it with the rosetta flag you can install the standalone via homebrew https://github.com/pact-foundation/homebrew-pact-ruby-standalone skip the binary install in the pact-js and copy them in manually (It might work if they are installed on the path, via homebrew). we also have the binaries on the website. There was a documented flag for that, I can't find it in the readme atm

yousafn
2022-04-19 21:13
I have these two things in my `.zshrc` so that if I use the alias `axbrew` I can download x86_64 packages from brew. The other flag passes in the platform flag to docker run and build otherwise I just had problems, I seem to be in a happy place now whether everything is working across both, I rarely use the rosetta shell. ```# useful only for Mac OS Silicon M1, # still working but useless for the other platforms docker() { if [[ `uname -m` == "arm64" ]] && [[ "$1" == "run" || "$1" == "build" ]]; then /usr/local/bin/docker "$1" --platform linux/amd64 "${@:2}" else /usr/local/bin/docker "$@" fi } # for intel x86_64 brew alias axbrew='arch -x86_64 /usr/local/homebrew/bin/brew'%```

yousafn
2022-04-19 21:15
The latest binaries are on the release page https://github.com/pact-foundation/pact-ruby-standalone/releases/tag/v1.88.83 This is obviously not the ideal method and there is something else up, which I would love to solve, but maybe this will get you going for now.

testingterrasoft
2022-04-19 21:21
Thanks a lot ! Will give it a try, starting from manually adding ) Path after installation of pac using npm is really empty - no version 1.88.83 created.. The last one - 1.88.81

yousafn
2022-04-19 21:40
yeah if the installation fails, it won't rebuild anything in your node_modules. I normally `rm -rf node_modules` to nuke it, before a reinstall if things have gone bork. Is your npm installation completing under the x86_64 arch? but failing under v3? and the same issues seen when trying under arm64?

testingterrasoft
2022-04-19 21:53
yep, for V3 - under x86_64 and arm64 error exactly the same

matt.fellows
2022-04-19 22:41
OK for t he V3 build, it uses Node Gyp. It looks like it?s not happy with spaces in your project path: ```npm ERR! AssertionError: Spaces in action input filenames not supported (/...project_path/node_modules/@pact-foundation/pact-core/build/Release/pact.node)```

matt.fellows
2022-04-19 22:42
Could you please try without any spaces in your working project folder? That will help us fix the problem, if possible

matt.fellows
2022-04-19 22:45
For the current stable build, can you please share an `npm i --verbose` output? (attach a file)

matt.fellows
2022-04-19 22:45
I suspect there is a different issue at play there. Is it a work laptop? It could be a proxy

olivia.c
2022-04-19 23:27
has joined #pact-js

testingterrasoft
2022-04-20 09:20
You are totally right, thanks ! Decision was near and much simple - spaces in path... Was small hint with V3 from python: ```AssertionError: Spaces in action input filenames not supported ``` In case with path without spaces: With stable version - working as expected both for x86_64 and arm64 With beta version - installation also correct In case of spaces: Logs for stable and beta version I attached

alanbos
2022-04-20 11:39
Hi - I've been running Atlassian bitbucket pipelines using the beta `@pact-foundation/pact` package for some time now without issue, but have suddenly run into this error when running tests after an `npm ci`: ```Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-core/build/Release/libpact_ffi.so) at Object.Module._extensions..node (internal/modules/cjs/loader.js:1131:18) at Module.load (internal/modules/cjs/loader.js:937:32) at Function.Module._load (internal/modules/cjs/loader.js:778:12) at Module.require (internal/modules/cjs/loader.js:961:19) at require (internal/modules/cjs/helpers.js:92:18) at bindings (/opt/atlassian/pipelines/agent/build/node_modules/bindings/bindings.js:112:48) at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-core/src/ffi/index.ts:6:21)``` If anyone has any clues as to what causes or fixes might be, I'd be glad to know - I've tried `10.0.0-beta.51` 58 and 59 all without success

matt.fellows
2022-04-20 12:26
Is the pipeline now running on a different image? It looks like you're missing a very standard Linux dependency - are you running alpine by any chance?

alanbos
2022-04-20 12:49
I was running one of the recommended (by Atlassian) node docker images, but have now switched to what they call their default image #3 (ubuntu LTS + other stuff), which seems to have cured it. I can understand why that might have fixed it, but can't understand why it suddenly broke.

matt.fellows
2022-04-20 13:06
You could inspect the pact library ( `.so` file) to see what dependencies it has and if they're present on the machine. That error suggests glibc is not present (or perhaps not the correct one). Is it possible the Ubuntu version has recently changed?

alanbos
2022-04-20 13:08
Its possible I guess - thanks for the pointers.

matt.fellows
2022-04-20 13:11
I don't believe we pin to a specific version of libc but it's possible. We definitely run builds on different systems that I would hope would shake that specific problem out

sebastianman45
2022-04-20 15:32
Hi @yousafn :sunglasses: How?s everything? maybe you've had the space to check this :see_no_evil:?, I have been trying to find the problem but have not found it :smiling_face_with_tear:

yousafn
2022-04-20 15:38
Hey @sebastianman45, I haven't sorry, I did take a cursory look and I loved your readme :chefkiss: . Promise to get it on the radar as soon as possible

yousafn
2022-04-20 15:39
Hiya, sorry buddy, it slipped me by, have replied to your original thread. We also had a long easter bank holiday off, but will get back to you asap rocky!

sebastianman45
2022-04-20 17:20
oh jeje thank you :partying_face::ok_hand:

victor.lau
2022-04-20 17:45
Hi. I received a test error for my consumer test that I?m not quite sure what is missing: ``` "relationships": Object { "identifiers": Object { "data": Array [ Object { - "id": Object { - "contents": "8", - "getValue": [Function getValue], - "json_class": "Pact::SomethingLike", - }, - "type": Object { - "data": Object { - "generate": "resource_identifiers", - "matcher": Object { - "json_class": "Regexp", - "o": 0, - "s": "^resource_identifiers$", + "id": "8", + "type": "resource_identifiers", }, - }, - "getValue": [Function getValue], - "json_class": "Pact::Term", - }, - }, ], },``` I wrote my response to be like this: ``` relationships: { identifiers: { data: [ { type: term({ generate: "resource_identifiers", matcher: "^resource_identifiers$" }), id: string('8'), }, ], }, treatments: like({ meta: like({ included: boolean(false), }), }), },``` Anyone have an idea of what I?m doing wrong? The test is just a simple : ``` const response = await fetch(`${provider.mockService.baseUrl}/procedures/2`, { headers }); const data = await response.json(); expect(data).toEqual({ data: {}, included: [dataFiltered], });```

victor.lau
2022-04-20 18:52
I guess I was expecting matchers to behave similarly as they do in Rspec `to match` with the same resolution as `to be_a(String)` nesting

yousafn
2022-04-20 19:54
hmm :thinking_face: , have you tried an array matcher? https://github.com/pact-foundation/pact-js#match-based-on-arrays

yousafn
2022-04-20 19:57
just pseudo code ```const { term, eachLike } = pact data: eachLike({ type: term({ generate: "resource_identifiers", matcher: "^resource_identifiers$" }), id: string('8') })```

ysuei.ygui
2022-04-20 20:42
has joined #pact-js

yousafn
2022-04-20 22:47
@sebastianman45 remove this line https://github.com/athan3350/pactjs-implementation/blob/019d3dcd5358676fd66960d3bb0f25fab4b6e948/__tests__/contract/consumer/get.consumer.spec.js#L12 `spec:2` as it in not generating the correct contracts, this is after removing that the provider side is amending the URL correctly. Btw there are some other things that will cause you issue in your test setup 1. Your consumer tests pass, even if you an an expectation that fails, such as expecting the body to some something or that the expected result. You can see the pact-verifier throwing an error,. 2. Your have fixed responses on your consumer side and you are testing against a live service, both of which are less than ideal. ```{ "consumer": { "name": "getidentityConsumer" }, "interactions": [ { "description": "I want to get a new identity with QR", "providerStates": [ { "name": "A message with a 200 OK with QR associated", "params": { "id": "50" } } ], "request": { "generators": { "path": { "expression": "/public/v2/posts/${id}/comments", "type": "ProviderState" } }, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "header": {}, "path": { "combine": "AND", "matchers": [ { "match": "type" } ] } }, "method": "GET", "path": "/public/v2/posts/101/comments" }, "response": { "body": [], "headers": { "Content-Type": "application/json" }, "status": 200 } }, { "description": "I want to get a new identity without QR", "providerStates": [ { "name": "A message with a 200 OK without QR associated", "params": { "id": "45" } } ], "request": { "generators": { "path": { "expression": "/public/v2/posts/${id}/comments", "type": "ProviderState" } }, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "header": {}, "path": { "combine": "AND", "matchers": [ { "match": "type" } ] } }, "method": "GET", "path": "/public/v2/posts/100/comments" }, "response": { "body": [ { "body": "Sed vel ad. Ea similique tempora. In a iusto.", "email": "", "id": 107, "name": "Rakesh Nair", "post_id": 100 } ], "headers": { "Content-Type": "application/json" }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.0.0-beta.59" }, "pactRust": { "ffi": "0.2.4", "models": "0.3.1" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "getidentityProvider" } }```

yousafn
2022-04-20 22:49
@matt.fellows if we set `spec: 2` in the provider v2 options, we get a `v1.1.0` spec generated. Looking at the types, neither of those are supported (allowing options are 3 and 4). ```{ "consumer": { "name": "getidentityConsumer" }, "interactions": [ { "description": "I want to get a new identity with QR", "providerState": "A message with a 200 OK with QR associated", "request": { "generators": null, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/101/comments" }, "response": { "body": [], "headers": { "Content-Type": "application/json" }, "status": 200 } }, { "description": "I want to get a new identity without QR", "providerState": "A message with a 200 OK without QR associated", "request": { "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/100/comments" }, "response": { "body": [ { "body": "Sed vel ad. Ea similique tempora. In a iusto.", "email": "", "id": 107, "name": "Rakesh Nair", "post_id": 100 } ], "headers": { "Content-Type": "application/json" }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.0.0-beta.59" }, "pactRust": { "ffi": "0.2.4", "models": "0.3.1" }, "pactSpecification": { "version": "1.1.0" } }, "provider": { "name": "getidentityProvider" } }```

abubics
2022-04-21 02:23
This looks like you're sending the matchers in your request/response. Which bit of the test is it complaining on?

abubics
2022-04-21 02:25
As an aside, I'd expect you to be writing contract tests against an API client that wraps the `fetch` call for you. Otherwise your tests might not be handling requests/responses the same way as your code :)

matt.fellows
2022-04-21 03:02
The matchers get applied when the provider side test runs. I.e. They are for matching the response of a provider - this is a consumer test so matchers on the response won't yet have any effect

matt.fellows
2022-04-21 03:23
Interesting. That might be a mapping issue Yousaf. I'll fix tonight, good pickup

matt.fellows
2022-04-21 08:23
OK just taken a look now. This interface actually accepts a `SpecificationVersion` enum, which correctly maps to the right spec. But because JS, you can shove any number in there. Because this maps to an underlying enum, it actually maps to 1.1 (hence the problem). It might need a guard added to the method to ensure only valid specs can be specified. I?ll have a think about a nice way of doing it

yousafn
2022-04-21 08:33
Hmmm, I wonder if ? we could spit out a warning when using that `v1` spec was used but no longer supported, ? if someone provides a spec version, but uses matchers/generators that aren't supported, when we throw an error. I think the 2nd point leads into the discussion around the pact specs and generators, trying to find the thread

yousafn
2022-04-21 08:37
This was the blurb, and link to the discussion. Got my thinking cap on > The feature support issue is still also a big challenge. The specification only governs the contract format and matching rules, but is silent on other behaviour (see also https://github.com/pact-foundation/pact-net/pull/380). > > So, to avoid incompatibility issues you have to know: > 1. What version of the client library you are on (what features it supports) > 2. What specification it supports (contract file compatibility) > 3. What are the versions of each of the providers you have (to determine feature support) > 4. What specification it supports (to determine if the contract file is compatible) > > That information isn?t accessible anywhere, and, it could be argued, is a lot to expect of a user

sebastianman45
2022-04-21 14:25
Hi @yousafn :wave: thanks for your help, you rock :sunglasses::ok_hand:, you are absolutely right with the change, I already see that the contract is generated with the id variable, but I see that when I run the provider the id variable does not change, (I try to change it to 100 so that the call at api returns an empty array), it is still making the call with the id variable set to 101, I already updated the repo https://github.com/athan3350/pactjs-implementation it could be clearer :grin:

yousafn
2022-04-21 14:50
You are calling a real end point and there is data there, not an empty array as you expect

yousafn
2022-04-21 14:51
You should be running your provider in isolation, so off the back of your injected data in your state handler, and you can control your providers response based on the value in the state handler

yousafn
2022-04-21 14:52
If you put Id of 999 you get some random data in that pre seeded api, and go to the browser for that Id you?ll see the same response

sebastianman45
2022-04-21 15:58
@yousafn yep, that is a dummy example, in my real project. I'm not pointing to a real API else to a code made in react, what I'm trying to do with this example is learn how to change parameters in my URL from the provider side.

sebastianman45
2022-04-21 16:00
but I see that the variable $id does not change on the provider side, it always stays at 101, maybe I'm doing something wrong :confused:

yousafn
2022-04-21 16:33
that is calling this URL https://gorest.co.in/public/v2/posts/999/comments and the errors are correct, you are trying to match a random response, against a fixed response encoded in your consumer test ```[2022-04-21T16:25:29Z DEBUG pact_matching::json] JSON -> JSON: Comparing '100' to '999' using Equality -> Err(Expected '100' to be equal to '999') [2022-04-21T16:25:29Z DEBUG pact_matching::json] compare_values: Comparing 'Number(100)' to 'Number(999)' at path '$[0].post_id' -> Err(["Expected '100' to be equal to '999'"])``` post ID 107 has an empty array https://gorest.co.in/public/v2/posts/100/comments ```2) Verifying a pact between getidentityConsumer and getidentityProvider Given A message with a 200 OK without QR associated - I want to get a new identity without QR 2.1) has a matching body $ -> Expected {"body":"Sed vel ad. Ea similique tempora. In a iusto.","email":"","id":107,"name":"Rakesh Nair","post_id":100} but was missing $ -> Expected a List with 1 elements but received 0 elements```



victor.lau
2022-04-21 21:43
Yup. I?m trying to reuse the same body for the request/response since its a large payload (our problem not Pact). We have an `axios` configuration that I didn?t want to fight in the test setup otherwise I would use the actual `fetch` we have implemented instead of the manual fetch. Agreed on the handling may not be the same way as my code, but it?s a risk I am accepting (and hopefully will not regret).

victor.lau
2022-04-21 21:44
It complained in the `ToEqual` portion, but the pact mock server did generate some data. I rewrote it to test a specific portion of the payload that I care mostly about. ``` const data = await response.json(); [ 'dob', 'phi_dob', 'email', 'first_name', 'full_name', 'gender', 'initials', 'last_name', 'middle_name', 'phone_number', ].map(field => { expect(data.included[0].attributes[field]).not.toMatch(/\*\*\*\*\*/); });```

victor.lau
2022-04-21 21:45
Got it. This makes sense. I was trying to figure out from JS documentation for an `any` matcher since I didn?t want to write a huge payload that I wasn?t testing for.

victor.lau
2022-04-21 21:47
I?m debating if I am doing a little bit of `functional testing` with what I am doing, but it seemed lightweight enough to use Pact for

abubics
2022-04-22 02:30
It's a bit hard to debug without seeing the whole test (because we can't see what the content of the operands in the expect are). But it looks like your `dataFiltered` includes matchers.

abubics
2022-04-22 02:33
There is a helper function in pact-js that can strip the matchers out, if you want to use that, rather than specify it again. But if you set your interaction up with flexible matchers, you don't need to re-test those with further assertions.

abubics
2022-04-22 02:34
In your initial test, I don't see any Pact-specific stuff, so I'm not really sure what to expect.

giuseppe.torchia
2022-04-22 08:25
has joined #pact-js

thadamski
2022-04-22 14:00
has joined #pact-js

druiz
2022-04-22 15:02
has joined #pact-js

tord.brokvist
2022-04-22 15:08
has joined #pact-js

druiz
2022-04-22 16:15
Hey @matt.fellows what am I doing wrong here that I'm getting the missing requests errors? I've tried the fixes mentioned in previous posts and no luck :disappointed: Below are the images for the service making the call, the pact config file, the pact test I'm running, and the error. This is an angular app running on Mac using the jest-pact package.

yousafn
2022-04-22 16:43
Not used Angular before, but that looking at the logs, your mock server is started up and listening on the correct port you are expecting to send your request to I thought jest-pact uses a random port now, and you passes the mock server base url that you inject into your api client code. looking at that, mock server log though, it's not getting a request, so is that subscribe method actually calling that line in your hello world program to make the request

gnanasekar69
2022-04-22 17:23
has joined #pact-js

himanshu.1046
2022-04-24 18:25
has joined #pact-js

florent
2022-04-25 04:41
Hello everyone. I am new and I found pact a really interesting tool for my company. Here I have a question I am using vue + cypress + pact to generate my pact. Everything works fine ! Now I am trying to be on the developer side. I am working on my feature that is suppose to call the api. What would the workflow for you ? In an ideal world you don't want to spin up the apis locally and run a mock server no? Same questions for api to api I will come back to the workshop tomorrow. But it's pretty new and a lot of informations to put in order

jgfarias42
2022-04-25 08:47
Hi folks, I am looking to run can-i-deploy using the pact-node library, but I cannot find the option to pass an _environment_ argument on the options. I see only the _to_ option, which checks for tags, but I don't see the equivalent to Broker's _--to-environment_ argument. Versions "@pact_foundation_greet/pact": "^9.17.2", "@pact_foundation_greet/pact-node": "^10.17.1",

matt.fellows
2022-04-25 09:12
I would just use the bundled CLI. I don't think we've added the latest flags. I'd like to deprecate this interface also but would accept a PR whilst we figure out the major release line

chris196
2022-04-25 09:51
has joined #pact-js

matt.fellows
2022-04-25 10:29
What do you mean by "developer side"?

matt.fellows
2022-04-25 10:30
I would recommend the workshop tho as you allude to. Those concepts and workflows should become more apparent

manu.vereecken
2022-04-25 11:06
has joined #pact-js

maltechristian.neuman
2022-04-25 11:52
has joined #pact-js

jgfarias42
2022-04-25 12:51
ok, thanks Matt. When I got some time, I will see if I can open a PR

florent
2022-04-25 13:35
when i say developer side is the person developing the feature

florent
2022-04-25 13:35
thanks yeah I am going to do that. It's just it's a lot of informations to digest

prashanth.ramadass
2022-04-25 14:04
has joined #pact-js

sebastianman45
2022-04-25 14:04
Hi @yousafn, Sorry I hadn't seen your message, you're right :heart:, I was looking at the logs wrong, thank you very much for your help (as always jejej), this helps me a lot :sunglasses::ok_hand:


druiz
2022-04-25 15:31
So I threw a console log in the service and it does look like the subscribe is calling the service. Here are some more logs. Hoping they look familiar and you know more about how to move forward from here :pray:

yousafn
2022-04-25 15:33
looks like there are no interactions loaded in the mock provider

yousafn
2022-04-25 15:35
any chance you could stick an example repo up on GH?

druiz
2022-04-25 15:36
yeah, I'll push the code up now and share link for GH one sec


druiz
2022-04-25 15:44
let me know if you have any issues accessing the repo

yousafn
2022-04-25 15:47
Can access it, can't install pact, using v3, as it pins peer deps to v24-v26 or jest https://github.com/pact-foundation/jest-pact/blob/a7b39380473e10b6939c89cbf8bd701f85bd513c/package.json#L61

yousafn
2022-04-25 15:48
will drop the jest version down in the dev dep which should sort it and get me installed :slightly_smiling_face:

druiz
2022-04-25 15:49
Yeah that works. I ran into that error as well and it was a lot of changing versions around so they would play nice together lol sorry about that

yousafn
2022-04-25 15:50
it's okay buddy. quick question, does your unit test work

yousafn
2022-04-25 15:50
might just be failing due to changing the port in the setupJest file, will grab a brew and spend 20 minutes having a poke around anyway

druiz
2022-04-25 15:52
The unit test does pass but its a false positive. You can change the expected value to anything and it will still be a success. This is a separate issue I'm looking into as I didn't think it was related/affected the pact test.

druiz
2022-04-25 15:53
Thank you I appreciate you taking a look :pray: There aren't any recent angular/cypress/jest/nx monorepo content out there so I'm hoping to get this working and write an article.

druiz
2022-04-25 15:54
Also, I have a nestJS api that I run locally to get that test to pass. Let me see if I can push it up in the GH as well. I initially thought I needed an API running for pact but the more I read it looked like there was no need for an api running locally. It was the pact mock server that would be returned the data essentially


yousafn
2022-04-25 15:57
monorepo stuff sounds cool, loads of people are asking for support for monorepos on my cypress plugins, and keep mentioning nx. I've got a group of various related plugins that I am planning on migrating a smaller subset of repos, because it's a pain maintaining them atm

druiz
2022-04-25 15:58
So I don't actually need pact for nestJS :disappointed: I'm not sure what the overlap is but my company needs pact testing on the Frontend - Angular app inside an nx monorepo that uses Jest and Cypress. We don't have any nestJS apps it was more me thinking I needed an API to provide data to get the pact tests to work.

druiz
2022-04-25 15:59
From my understanding though you stub some data and then feed that into Pact so when the Pact test hits the Pact mock server it returns the stubbed data I fed it.

yousafn
2022-04-25 16:01
correct, but the pact mock service, will check when it receives the request, was it the type of request you explicitly stated in your test, if so, it will return the prescribed data, for your client code to unmarshall, and for you to test the response of your clients code result (not that of the providing api)

druiz
2022-04-25 16:04
Yup that's exactly how I understood it. So there isn't a need for a providing api which would be the localhost:3333 endpoint you're seeing in the unit test. Is there some overlap between the unit test you ran and the pact test that is run with the "npm run test:pact" command?

druiz
2022-04-25 16:05
I assumed they had nothing to do with each other really. That they're two completely separate concerns with no dependency on each other. Is that correct?

yousafn
2022-04-25 16:05
so your unit test, effectively is a component integration test, with a mock of the provider. Pact is used within your unit test framework. You wouldn't use Pact in all your test cases, but a select few

druiz
2022-04-25 16:10
I'm not quite sure I follow :sweat: The unit test that's currently in there can be disregarded no? We can just delete it if it's causing any confusion. I had only created it thinking it was needed for the Pact test.

yousafn
2022-04-25 16:13
Yeah I don't think it's needed. this shows it quite nicely https://github.com/pact-foundation/jest-pact#usage I just started there, to ensure that we were mocking the call in the unit test correctly to whichever endpoint our api client service (in this case HelloWorldService) The non pact test doesn't look right as I can expect the result to be anything, and it passes. (as you said)

druiz
2022-04-25 16:16
Oh I see what you're saying about ensuring we're mocking the call correctly. Yeah I had just thrown a console log in there to make sure the .subscribe() method actually called the service which it did. I'm also assuming the get request in the helloworldservice works correctly as well since if I run the api locally it does indeed return data when I call that service

druiz
2022-04-25 16:17
So this is the pickle I'm in now, I'm not sure why Pact isn't picking up the fact that we're making a request. My only theory is that there is something wrong in the config as far as where we're pointing that request/endpoint.

druiz
2022-04-25 16:19
I've tried passing in the entire pact mock server endpoint in the get request - e.g. http://localhost:8181/hello and http://127.0.0.1:8181/hello as well as passing in just the path - e.g. '/hello'

druiz
2022-04-25 16:20
Nothing seems to work :sob:

yousafn
2022-04-25 16:21
I don't think you are mocking things out correctly in angular

yousafn
2022-04-25 16:23
The pact bit might add more complexity, but looking the the angular docs https://angular.io/api/common/http/testing/TestRequest#flush flush should resolve the request by returning whatever you put in you have `req.flush(expectedResult);` but in your service.helloWorld subscriber, you can expect the result to be anything.

yousafn
2022-04-25 16:23
everything is voodoo with automagic dependency injection

victor.lau
2022-04-25 16:27
Is there a chance for a `any` matcher? E.g. ```relationships: any({}),``` so that it could be any object with attributes

druiz
2022-04-25 16:33
I push up the new changes to the GH that include what you mentioned. It looks like I'm still getting the same error :disappointed:

yousafn
2022-04-25 16:37
I removed the v3 version of pact and installed these ``` "@pact-foundation/pact": "^9.17.3", "jest-pact": "^0.9.3",```

yousafn
2022-04-25 16:37
`npm i -d @pact-foundation/pact jest-pact`

yousafn
2022-04-25 16:37
let me fork your repo and drop a PR

druiz
2022-04-25 16:41
Omg dude you're the best!! Curious if this was an issue with the Url I was stubbing or the versioning? I had moved over to the the beta version due to an error in the console saying v2 wasn't supported for x thing. I can't quite remember off the top of my head.

yousafn
2022-04-25 16:43
the only reason you can't use v3 at the moment, is it fixed jest deps to v26 or lower, and if I drop your jest dep, I need to tweak your tests

yousafn
2022-04-25 16:43
will put on my radar to update the pact v3 branch so it tested with jest 27 and released


yousafn
2022-04-25 16:48
I can imagine this opens up a huge can of worms I wonder if this may fall into the camp of why there is no support for specify optional attributes https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes If that didn't apply, if you said it was any object, how would a provider validate/match against any object, would they just provide any object back?

yousafn
2022-04-25 16:48
If you have an example of the particular use case, that would be great!

yousafn
2022-04-25 16:49
the real clincher is the injection of the url, jest-pact spins you up a mock server on a random port, so inject that into your api client and boom :thumbsup: look forward to your article fella

druiz
2022-04-25 16:57
Dude awesome thank you so much! I'm going to start writing the initial article now that gets angular/jest working with Pact. From there I'll move onto Cypress and then finally tie it all up into a monorepo env. Can't thank you enough for getting me over this initial hill :heart:

yousafn
2022-04-25 17:03
Sounds awesome matey, and my pleasure my friend. I have a cypress example with mocks provided by msw and pacts generated with our adapter. Quick start guide is here (hot off the press) https://docs.pactflow.io/docs/bi-directional-contract-testing/tools/msw/ We also have a cypress adapter https://github.com/pactflow/pact-cypress-adapter And an example repo that uses it. https://docs.pactflow.io/docs/examples/bi-directional/consumer/cypress/ Would love to get an angular recipe on the pact docs site at some point https://docs.pact.io/recipes and give this page some general love

brendan.j.donegan
2022-04-25 20:32
It feels like if your consumer doesn't care what relationships is then it's not actually using it and therefore shouldn't be in the contract

brendan.j.donegan
2022-04-25 20:33
Pact is not meant to be a general API validation framework

victor.lau
2022-04-25 20:45
It?s an issue we are aware of. It?s just that until we migrate away from over-fetching it?d be nice to ignore some attributes

brendan.j.donegan
2022-04-25 20:47
But just because you fetch a property doesn't mean you *use* it. The question to ask is "if the API never returned this property, what would happen to my consumer?" If the answer is "nothing", you don't need it

victor.lau
2022-04-25 20:47
Use case would be that a certain part of the payload has been masked. I am still retrieving a lot from the payload, but I?m most interested in a specific section

brendan.j.donegan
2022-04-25 20:48
If the answer is "well it crashes, or can't perform some expected function" you probably do

victor.lau
2022-04-25 20:48
To be clear, I?m not arguing for having the attribute in. It?s just that until I migrate away from the overfetching/attribution (since a lot of other consumers use this 1 massive endpoint). I?d like to keep it in

brendan.j.donegan
2022-04-25 20:49
Are you the provider maintainer?

victor.lau
2022-04-25 20:49
I am for now.

brendan.j.donegan
2022-04-25 20:49
And you're writing the consumer contracts?

victor.lau
2022-04-25 20:50
Until we split out the teams yes

janarthanan.rajendras
2022-04-25 22:35
has joined #pact-js

matt.fellows
2022-04-25 22:54
For the workflow, this is the canonical one: https://docs.pact.io/pact_nirvana

matt.fellows
2022-04-25 23:01
Another option is to consider something like Pactflow?s https://docs.pactflow.io/docs/bi-directional-contract-testing. This might be more appropriate for a provider-driven approach

abubics
2022-04-26 01:16
> To be clear, I?m not arguing for having the attribute in. It?s just that until I migrate away from the overfetching/attribution [...] I?d like to keep it in Basically, if you don't need the attribute, you can leave it out. If you need something in its children, put it in. You don't have to specify all of the child attributes either, just the ones that are load-bearing :slightly_smiling_face:

shreyas.gowda
2022-04-26 02:14
has joined #pact-js

marxjo
2022-04-26 07:09
has joined #pact-js

andrew.fraser
2022-04-26 07:19
has joined #pact-js

lei.shi
2022-04-26 07:46
has joined #pact-js

akash.sharma5253
2022-04-26 11:50
has joined #pact-js

druiz
2022-04-26 16:51
Hey @yousafn I just noticed some weird behavior when running the pact tests. The Pact test will pass and then when I run the pact test again it will randomly fail all of a sudden? Even though I didn't change anything. I kept running the Pact test and it took me 5 tries before the pact test passed again. Heres a link to the Github repo with the latest code - https://github.com/damianavid/angular-pact

yousafn
2022-04-26 17:27
I wont have time to look at this so you are on your on for now buddy, but if I get some this week, i'll take a look. I would revert back to that commit of the PR as there are some additional changes there

druiz
2022-04-26 17:33
No worries. I should be able to keep going as the test will occasionally show a success. I just wanted to bring it to your attention since even reverting back to your PR it still shows the same behavior. If I continue to run the pact test it won't pass 100% of the time. It almost seems random. e.g. one fail one pass, four fails, one pass, etc, etc.

matt.fellows
2022-04-26 21:46
Sounds like promises or a misconfiguration.


kannan.jai
2022-04-27 07:49
has joined #pact-js

c.giannakopoulos
2022-04-27 10:47
has joined #pact-js

sebastian.spiess
2022-04-27 11:43
has joined #pact-js